加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

如何用curl做keepalive http请求?

发布时间:2020-12-13 19:18:25 所属栏目:Linux 来源:网络整理
导读:如何在同一连接中从同一Web服务器请求多个页面? 因此客户端需要为每个请求提取响应,当然服务器的工作就是按照请求的顺序进行响应. 谁知道诀窍? 解决方法 我不知道你是否真的意味着“并发”,但从描述中我相信你只想重用连接.如果只是对同一服务器执行两个请
如何在同一连接中从同一Web服务器请求多个页面?

因此客户端需要为每个请求提取响应,当然服务器的工作就是按照请求的顺序进行响应.

谁知道诀窍?

解决方法

我不知道你是否真的意味着“并发”,但从描述中我相信你只想重用连接.如果只是对同一服务器执行两个请求,则应重用该连接

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,"http://example.com/docs/");
res = curl_easy_perform(curl);

以下是输出的部分内容:

* 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)

编辑根据评论

在这种情况下,您需要多接口.多重联系说:

Enable multiple simultaneous transfers in the same thread without
making it complicated for the
application.

有关示例,请参阅multi-double.c(“只需下载两个HTTP文件!”).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读