Jump to content

[C] Webrequest


Carlos Barros

Recommended Posts

Boa tarde,

Eu gostaria de saber como fazer um WebRequest em C.

por exemplo em C#:

		 ASCIIEncoding enconding = new ASCIIEncoding();
		 String postData = "ip=" + ip + "&name=" + name;
		 byte[] data = enconding.GetBytes(postData);
		 WebRequest request = WebRequest.Create("http://localhost/insert.php");
		 request.Method = "POST";
		 request.ContentType = "application/x-www-form-urlencoded";
		 request.ContentLength = data.Length;
		 Stream stream = request.GetRequestStream();
		 stream.Write(data, 0, data.Length);
		 stream.Close();
		 WebResponse response = request.GetResponse();
		 stream = response.GetResponseStream();
		 StreamReader sr = new StreamReader(stream);
		 MessageBox.Show(sr.ReadToEnd());
		 sr.Close();
		 stream.Close();

PS: Eu gostaria de saber como fazer em C e NÃO C#.

Obrigado

Edited by Carlos Barros
Link to comment
Share on other sites

Tens que usar uma biblioteca, por exemplo: libcurl.

Se preferes fazer tudo "à pata" (com sockets), aconselho-te uma leitura do "Beej's Guide to Network Programming".

What have you tried?

Não respondo a dúvidas por PM

A minha bola de cristal está para compor; deve ficar pronta para a semana.

Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.