does httplib reuse TCP connections? [duplicate]

泪湿孤枕 提交于 2019-12-05 17:51:55

your example creates a new TCP connection each time through the loops, so no, it will not reuse that connection.

How about this?

con = httplib.HTTPConnection("myweb.com")
while True:
    con.request("GET", "/x.css", headers={"Connection":" keep-alive"})
    result = con.getresponse()
    result.read()
    print result.reason, result.getheaders()

also, if all you want is headers, you can use the HTTP HEAD method, rather than calling GET and discarding the content.

It certainly can't reuse the connection if you scrap the HTTPConnection object every time through the loop …

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!