使用pycurl的自定义标头

时间:2010-06-15 11:45:53

标签: python header pycurl

我可以使用pycurl请求向服务器发送自定义标头,例如“yaddayadda”吗?

3 个答案:

答案 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)