python requests - POST Multipart/form-data without filename in HTTP request

前端 未结 2 1623
失恋的感觉
失恋的感觉 2020-12-13 02:24

I am trying to replicate the following POST request using the requests module in python:

POST /example/asdfas HTTP/1.1
Host: example.com
User-Agent: Mozilla/         


        
2条回答
  •  伪装坚强ぢ
    2020-12-13 02:59

    import requests
    from requests_toolbelt import MultipartEncoder
    
    url = 'http://example.com/example/asdfas'
    fields = {'value_1':'12345', 'value_2': '67890'}
    
    data = MultipartEncoder(fields=fields)
    headers["Content-type"] = m.content_type
    
    requests.post(url=url, data=data, headers=headers)
    

提交回复
热议问题