y2k
y2k

Reputation: 65996

Are there any CURL alternatives for C++?

I hate CURL it is too bulky with too many dependencies when all I need to do is quickly open a URL. I don't even need to retrieve the contents of the web page, I just need to make the GET HTTP request to the server.

What's the most minimal way I can do this and don't say CURL !@#$

Upvotes: 3

Views: 10087

Answers (5)

Peter Olsson
Peter Olsson

Reputation: 1322

I have used Winsock when I need as few dependencies as possible and it has worked well. You need to write more code than using a separate library or the Microsoft WinHTTP library.

The functions you need are WSAStartup, socket, connect, send, recv, closesocket and WSACleanup.
See sample code for the send function.

Upvotes: 0

Indy9000
Indy9000

Reputation: 8851

On Windows (Windows XP, Windows 2000 Professional with SP3 and above) you could use WinHttpReadData API. There's also an example at the bottom of that page.

More info on Windows HTTP Services on MSDN

Upvotes: 3

PP.
PP.

Reputation: 10864

There's a very light way and I've done this myself when implementing a high-scale back end service for a large media provider in the UK.

This method is extremely operating-system specific.

  1. open a TCP socket to the HTTP server
  2. send a "GET /path/to/url HTTP/1.1\r\nHost: www.host.com\r\n\r\n" (the Host header is required for HTTP/1.1 and most virtual servers, don't forget the two blank lines, and a newline requires a carriage return as well for HTTP headers)
  3. wait for the response
  4. close the socket

If you are going to close the socket at the end of the connection you may also want to send a Connection: close\r\n as part of your headers to inform the web server that you will terminate the connection after retrieving the web page.

You may run into trouble if you're fetching an encoded or generated web page in which case you'll have to add logic to interpret the fetched data.

Upvotes: 4

Carl Smotricz
Carl Smotricz

Reputation: 67760

system("wget -q -O file.htm http://url.com");

Upvotes: -3

John Feminella
John Feminella

Reputation: 311526

There are lots of choices! Try libwww -- but be warned, most people strongly prefer libcurl. It's much easier to use.

Upvotes: 7

Related Questions