使用不同服务器上的会话保持活动连接的行为

时间:2018-06-21 20:58:31

标签: python python-requests

我正在使用python请求库发出发布请求,

with requests.Session() as sess:
    req = requests.Request('POST', url, data=query)
    prepped= req.prepare()
    resp = sess.send(prepped)
    return resp

这是发出请求后的响应头,

{'Content-Encoding': 'gzip', 'Transfer-Encoding': 'chunked', 'Expires': '0', 'Vary': 'Accept-Encoding, User-Agent', 'Server': 'Jetty(8.1.16.v20140903)', 'Pragma': 'no-cache', 'Cache-Control': 'no-cache', 'Access-Control-Allow-Origin': '*', 'Content-Type': 'application/json; charset=UTF-8'}

请求文档提到由于urllib3,会话对象默认情况下进行保持活动连接。所以我想知道为什么我不能在响应头中看到连接保持活动。

  

请求库版本:   /usr/local/lib/python2.7/dist-packages/requests-2.18.4.dist-info

更新 通过上面的代码段发出以下请求后,我可以在响应中看到Connection保持活动状态,

req = requests.Request('POST', 'https://postman-echo.com/post', data='This is expected to be sent back')

{'Content-Length': '234', 'set-cookie': 'stuff here; Path=/; HttpOnly', 'Vary': 'Accept-Encoding', 'Server': 'nginx', 'Connection': 'keep-alive', 'ETag': 'W/"stuff here"', 'Date': 'Thu, 21 Jun 2018 22:03:41 GMT', 'Content-Type': 'application/json; charset=utf-8'}

以上两个代码段之间的区别是端点和请求,这是否意味着第一台服务器不支持Keep-alive?

0 个答案:

没有答案