我尝试使用以下代码在Python 3.2.3中保持与urllib.request的HTTP连接:
handler = urllib.request.HTTPHandler()
opener = urllib.request.build_opener(handler)
opener.addheaders = [("connection", "keep-alive"), ("Cookie", cookie_value)]
r = opener.open(url)
Run Code Online (Sandbox Code Playgroud)
但是,如果我听到与Wireshark的连接,我会得到一个带有"Connection:closed"的Header但是设置了Cookie.
Host: url
Cookie: cookie-value
Connection: close
Run Code Online (Sandbox Code Playgroud)
如何将Headerinfo设置为Connection:keep-alive?