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.
Please advise if there as such any C++ library to achieve this asynchronous HTTP client feature.
libcurl's "multi" interface can run HTTP requests in the background (it uses a 2nd thread, but the effect is the same). First, create a multi handle with 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_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. Don't forget to call curl_multi_cleanup
when you're done.
http://curl.haxx.se/libcurl/c/libcurl-multi.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With