Python send POST with header

前端 未结 3 1399
独厮守ぢ
独厮守ぢ 2020-12-02 16:10

I try to build a python script who sends a POST with parameters for extracting the result. With fiddler, I have extracted the post request who return that I want. The websit

3条回答
  •  借酒劲吻你
    2020-12-02 17:07

    If we want to add custom HTTP headers to a POST request, we must pass them through a dictionary to the headers parameter.

    Here is an example with a non-empty body and headers:

    import requests
    import json
    
    url = 'https://somedomain.com'
    body = {'name': 'Maryja'}
    headers = {'content-type': 'application/json'}
    
    r = requests.post(url, data=json.dumps(body), headers=headers)
    

    Source

提交回复
热议问题