Custom headers with pycurl

家住魔仙堡 提交于 2019-12-20 17:19:12

问题


Can I send a custom header like "yaddayadda" to the server with the pycurl request?


回答1:


I would code something like:

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()



回答2:


you can, with HTTPHEADER. just provide your custom headers as a list, like so:

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

curl.setopt(pycurl.HTTPHEADER, header)




回答3:


Try to use human_curl library 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)


来源:https://stackoverflow.com/questions/3044782/custom-headers-with-pycurl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!