我应该使用什么 C++ 库来实现 HTTP 客户端?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/822581/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 17:26:39  来源:igfitidea点击:

What C++ library should I use to implement a HTTP client?

c++httpclient

提问by Piotr Dobrogost

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

我正在寻找一个实现或启用 HTTP 客户端实现的 C++ 库。它也应该处理 cookie。

What would you propose?

你会提出什么建议?

采纳答案by bdonlan

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

Curl++: 是一个选项,特别是如果你想要更多的 C++ 风格的东西。

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

cpp-netlib: 非常好用且简单易用,可在 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_);

回答by da_m_n

Take a look at Poco Libraries.

看看Poco 图书馆

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.

我开始使用它们,因为它们是便携式的,使用起来很愉快。简单而干净——虽然我暂时没有做任何花哨的事情。

回答by The Unknown

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

默认情况下,C++ (STL) 没有 HTTP 或网络库,您将不得不做其他事情。

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

libcurl应该做你想做的。cURL++与包裹在闪亮的 C++ 包装器中的 libcurl 相同。

回答by Eugene

You can try WinInet

你可以试试 WinInet

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

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

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

与 WinHTTP 相比,它更面向客户端。

回答by Eugene

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

如果是 Windows,请查看 Windows HTTP Services (WinHTTP)

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

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.

Microsoft Windows HTTP 服务 (WinHTTP) 为开发人员提供了 HTTP 客户端应用程序编程接口 (API),以通过 HTTP 协议将请求发送到其他 HTTP 服务器。

WinHTTP 提供适用于基于 Active Server Pages (ASP) 的应用程序的 C/C++ 应用程序编程接口 (API) 和组件对象模型 (COM) 自动化组件。

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

对于 Cookie http://msdn.microsoft.com/en-us/library/aa383261(VS.85).aspx

回答by Neil Han

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

此处提供所有替代库,如果您需要复杂的 http API,请尝试 curl,如果只想获取文件,请尝试 http-tiny

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

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

回答by Eugene Yokota

On Windows you can drive IE using IWebBrowser2interface.

在 Windows 上,您可以使用IWebBrowser2界面驱动 IE 。