How to make a permanent http request with curl?

How can I request multiple pages from the same web server on the same connection?

Thus, the client side needs to retrieve the response for each request, of course, this is the serverโ€™s job to make the answer in the same order as requested.

Does anyone know a trick?

+6
source share
1 answer

I donโ€™t know if you really meant โ€œsimultaneousโ€, but from the description, I believe that you just want to reuse the connection. If you just perform two requests on the same server, it should reuse the connection

persistant.c

 /* get the first document */ curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/"); res = curl_easy_perform(curl); /* get another document from the same server using the same connection */ curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/docs/"); res = curl_easy_perform(curl); 

Here are the output particles:

 * About to connect() to example.com port 80 (#0) * Trying 192.0.32.10... * connected * Connected to example.com (192.0.32.10) port 80 (#0) [...] * HTTP/1.0 connection set to keep alive! < Connection: Keep-Alive Connection: Keep-Alive [...] * Connection #0 to host example.com left intact * Re-using existing connection! (#0) with host example.com * Connected to example.com (192.0.32.10) port 80 (#0) 

EDIT In light of the comment

In this case, you need a multi interface. multi interafce says:

Enable multiple simultaneous transfers in the same thread without which complicates the application.

See multi-double.c ("Just upload two HTTP files!") For an example.

+6
source

Source: https://habr.com/ru/post/888745/


All Articles