25

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

4

3 回答 3

52

我会编写如下代码:

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()
于 2010-06-15T12:11:52.580 回答
5

您可以使用 HTTPHEADER。只需将您的自定义标题作为列表提供,如下所示:

header = ['test: yadayadayada', 'blahblahblah']

curl.setopt(pycurl.HTTPHEADER, header)

于 2010-06-15T12:15:58.867 回答
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)
于 2011-09-01T11:42:00.810 回答