50

I'm looking for a C++ library that implements or enables the implementation of a HTTP client. It should handle cookies as well.

What would you propose?

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
Piotr Dobrogost
  • 41,292
  • 40
  • 236
  • 366

8 Answers8

40

Curl++: is an option, particularly if you want things in more of a C++ style.

cpp-netlib: very good and simple to use, available on ubuntu

sudo apt-get install libcppnetlib-dev

example:

using namespace boost::network;
using namespace boost::network::http;

client::request request_("http://127.0.0.1:8000/");
request_ << header("Connection", "close");
client client_;
client::response response_ = client_.get(request_);
std::string body_ = body(response_);
KindDragon
  • 6,558
  • 4
  • 47
  • 75
bdonlan
  • 224,562
  • 31
  • 268
  • 324
18

Take a look at Poco Libraries.

I started using them as they are portable and it's a joy to work with. Simple and clean - though I haven't dived in anything fancy for the moment.

da_m_n
  • 821
  • 7
  • 10
16
dfa
  • 114,442
  • 31
  • 189
  • 228
12

C++ (STL) does not have a HTTP or network library by default, you will have to do with something else.

libcurl should do what you want. cURL++ is the same libcurl wrapped in a shiny C++ wrapper.

The Unknown
  • 19,224
  • 29
  • 77
  • 93
3

You can try WinInet

http://msdn.microsoft.com/en-us/library/aa385331(VS.85).aspx

In contrast to WinHTTP, it's more client-side oriented.

Eugene
  • 3,335
  • 3
  • 36
  • 44
  • 1
    Thanks for your suggestion. Take a look at my comment on WinHTTP answer on this question as it applies here as well. "// This call will fail on the first pass, because // no buffer is allocated. if(!HttpQueryInfo(hHttp,HTTP_QUERY_RAW_HEADERS_CRLF, (LPVOID)lpOutBuffer,&dwSize,NULL))" "For ease of use, WinINet abstracts these protocols into a high-level interface." High-level interface? Maybe it was high-level interface 20 years ago... – Piotr Dobrogost May 05 '09 at 07:55
  • You can also look at URL monikers: http://msdn.microsoft.com/en-us/library/ms774965(VS.85).aspx, it relies on WinInet(as I think), but provides COM like interface. – Eugene May 05 '09 at 09:58
  • @Piotr: trust me, if you think WinHTTP is bad, you will absolutely *HATE* WinInet... It is an astonishingly unfriendly API, even if you're used to working with C libraries. And the worst part of it may be the WinInet constants and errors that "bleed through" to higher-level libraries such as MSXML... The big advantage of WinInet is that if a user has already configured proxy settings for their account (via the administrator options or the IE / Internet Options control panel) then WinInet will pick those up automatically; other libraries may need explicit configuration. Windows-only though... – Shog9 Jan 27 '10 at 19:05
  • and wininet could popup gui's reqiuring user to do something – TakeMeAsAGuest Mar 29 '19 at 20:32
2

If it's for windows, take a look at Windows HTTP Services (WinHTTP)

http://msdn.microsoft.com/en-us/library/aa384273(VS.85).aspx

Microsoft Windows HTTP Services (WinHTTP) provides developers with an HTTP client application programming interface (API) to send requests through the HTTP protocol to other HTTP servers.

WinHTTP offers both a C/C++ application programming interface (API) and a Component Object Model (COM) automation component suitable for use in Active Server Pages (ASP) based applications.

For Cookies http://msdn.microsoft.com/en-us/library/aa383261(VS.85).aspx

  • Thanks for your suggestion. It's plain C without any of C++ there. I'd really like to make use of Bjarne's hard work (http://research.att.com/~bs). It should be forbidden for a couple of years now to use C in application programming :) – Piotr Dobrogost May 05 '09 at 07:45
2

All alternative library are available here, if you need complex http APIs, try curl, if just wanna get a file, try http-tiny

http://curl.haxx.se/libcurl/competitors.html

Neil Han
  • 91
  • 1
  • 5
1

On Windows you can drive IE using IWebBrowser2 interface.

Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319