45

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
  • 28,703
  • 48
  • 145
  • 221
Piotr Dobrogost
  • 39,915
  • 36
  • 232
  • 353

8 Answers8

36

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,099
  • 4
  • 46
  • 74
bdonlan
  • 214,833
  • 29
  • 259
  • 321
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
15
dfa
  • 111,277
  • 30
  • 187
  • 226
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
  • 18,326
  • 29
  • 72
  • 92
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,128
  • 3
  • 36
  • 42
  • 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
  • 92,933
  • 45
  • 208
  • 312