我可以使用pycurl请求向服务器发送
答案 0 :(得分:46)
我的代码如下:
pycurl_connect = pycurl.Curl()
pycurl_connect.setopt(pycurl.URL, your_url)
pycurl_connect.setopt(pycurl.HTTPHEADER, ['header_name1: header_value1',
'header_name2: header_value2'])
pycurl_connect.perform()
答案 1 :(得分:3)
你可以使用HTTPHEADER。只需将您的自定义标题提供为列表,如下所示:
header = ['test: yadayadayada', 'blahblahblah']
curl.setopt(pycurl.HTTPHEADER, header)
答案 2 :(得分:3)
尝试使用human_curl库https://github.com/Lispython/human_curl
custom_headers = (
('Test-Header', 'fwkjenwkljbnfkjqnewfrjven3lrf'),
('Another-Header', 'ifenwqnfe;wnfqfjlweqnnlf')
)
r = human_curl.get("http://stackoverflow.com",
headers=custom_headers)