Python 3如何将标头添加到urllib OpenerDirectory对象

时间:2019-04-30 17:43:08

标签: python-3.x python-3.6 urllib

在我的代码中,我有以下内容:

parse

运行我在Fiddler中看到的代码时,标题Content-Type和Connection与我上面指定的不一样;相反,它们如下:

http_headers = [
    ("Content-Type", "text/xml; charset=UTF-8"),
    ("Connection", "keep-alive"),
    ("User-Agent", "HttpApp/1.0")
]

opener = build_opener(HTTPCookieProcessor(), ProxyHandler({'http': 'http://127.0.0.1:8888'}))  # Fiddler port
default_opener.addheaders = http_headers

response = opener.open(fullurl="<URL>", data=data)

0 个答案:

没有答案