Jump to content
Carlos Barros

[C] Webrequest

Recommended Posts

Carlos Barros

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);
		 WebResponse response = request.GetResponse();
		 stream = response.GetResponseStream();
		 StreamReader sr = new StreamReader(stream);

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


Edited by Carlos Barros

Share this post

Link to post
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!

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.