Custom headers with pycurl

前端 未结 3 1873
南方客
南方客 2021-02-07 01:38

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

相关标签:
3条回答
  • 2021-02-07 01:55

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

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

    curl.setopt(pycurl.HTTPHEADER, header)

    0 讨论(0)
  • 2021-02-07 02:05

    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)
    
    0 讨论(0)
  • 2021-02-07 02:17

    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()
    
    0 讨论(0)
提交回复
热议问题