[英]C++ library for Asynchronous HTTP Client
I am looking for a C++ library to send an asynchronous HTTP request such that main thread is not blocked and notified later once http url request is done. 我正在寻找一个C ++库来发送异步HTTP请求,这样主要线程就不会被阻止,并且一旦http url请求完成就会被通知。
Please advise if there as such any C++ library to achieve this asynchronous HTTP client feature. 请告知是否有任何C ++库来实现此异步HTTP客户端功能。
libcurl's "multi" interface can run HTTP requests in the background (it uses a 2nd thread, but the effect is the same). libcurl的“多”接口可以在后台运行HTTP请求(它使用第二个线程,但效果相同)。 First, create a multi handle with
curl_multi_init
. 首先,使用
curl_multi_init
创建一个多句柄。 Then, set up an easy handle (create it with curl_easy_init
and set the URL and other options with curl_easy_setopt
) and call curl_multi_add_handle
. 然后,建立一个简单的句柄(与创建
curl_easy_init
并设置URL,并与其他选项curl_easy_setopt
)和呼叫curl_multi_add_handle
。 curl_multi_perform
will start the transfer(s) and return immediately, and you can call curl_multi_info_read
to get the status of your easy handles. curl_multi_perform
将启动传输并立即返回,您可以调用curl_multi_info_read
来获取简易句柄的状态。 Don't forget to call curl_multi_cleanup
when you're done. 完成后别忘了打电话给
curl_multi_cleanup
。
http://curl.haxx.se/libcurl/c/libcurl-multi.html http://curl.haxx.se/libcurl/c/libcurl-multi.html
The library doesn't have to be asynchronous. 该库不必是异步的。 As long as it is thread safe, you should be able to do whatever you need to do in a separate thread and use thread primitives to sync up later with the main thread..
只要它是线程安全的,你应该能够在一个单独的线程中做你需要做的任何事情,并使用线程原语稍后与主线程同步。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.