3

I need to sent a HTTP GET Request to my site and then get the contents of the page and parse it. I'de prefer to not use libraries like libCURL because I want the end application to be fully independent (This is quoting from personal experience, I may be wrong but if I recall the client has to have certain Dynamic Link Libraries to run applications with libCURL libraries.), I'm using C++ in Visual Studio 2012.

Code examples would also be good.

Ryan
  • 937
  • 5
  • 16
  • 33
  • Are you asking how to use winsock2 ? – nurettin Dec 22 '12 at 16:36
  • Open a socket(), send() your request, recv() your answer.. What have you tried already? Where are you stuck? How can we help you? – cmc Dec 22 '12 at 16:38
  • 4
    You can always statically link libcurl instead of dynamically linking it if you don't want to deal with distributing DLLs. – Adam Rosenfield Dec 22 '12 at 16:48
  • You want to use libCurl. Doing HTTP request may seem trivial if it works but if you diverge from normal by any amount the shit starts to happen very quickly. – Martin York Dec 22 '12 at 18:46

2 Answers2

8

When you don't want to use an external library, you will have to implement HTTP yourself. When you only need the basic functionality (direct download of a file, no redirects, no proxies, no cookies, no authentication, no encryption, no compression, no other shenanigans), this isn't even that hard.

Create a socket, connect it to port 80 of your webserver, and send the following strings to the server:

"GET /example.html HTTP/1.1\r\n"
"Host: www.example.com\r\n"
"\r\n"

This requests the file www.example.com/example.html from the server you connected to.

The server will respond with an own HTTP response header followed by the data (or an error description).

Philipp
  • 64,526
  • 9
  • 115
  • 146
3
  1. Most libraries can be compiled statically. When you use a static library it gets linked in into your executable and you do not have to ship the library's dll. Maybe this would help: Walkthrough: Creating and Using a Static Library (C++)
  2. Some libraries can be header-only or used in a header-only mode: compiler pulls the library into your source. Again, no dll is generated for the library. For example, you can try getting Asio and cpp-netlib to work in a header-only mode for you. There is also a sampe of a simple http client just for the Asio lying somewhere.
  3. I think you can use WinINet or WinHTTP without shipping any DLLs.
Paul
  • 110
  • 2
  • 10
ArtemGr
  • 10,505
  • 2
  • 46
  • 78
  • 2
    The WinInet/WinHTTP DLLs are already installed in the OS. You do not need to deploy the DLLs yourself, but they are still DLLs nontheless. – Remy Lebeau Dec 22 '12 at 18:39