Tools, FAQ, Tutorials:
Sending an HTTP POST Request
How to send an HTTP POST request? I want to submit a form to a Website.
✍: FYIcenter.com
To submit a form to a Website, you can use the requests.post() function:
>>> r = requests.post(url, data = {'key':'value'})
The second argument 'data' is a 'dict' object contains of the list of form field names and values.
Here is a Python example on how to send a POST request and print the response body in JSON formation:
>>> import requests >>> form = {'userid':'fyi', 'password':'center'} >>> r = requests.post('http://httpbin.org/post',data=form) >>> j = r.json() >>> print(j) {'args': {}, 'data': '', 'files': {}, 'form': {'password': 'center', 'userid': 'fyi'}, 'headers': { 'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Content-Length': '26', 'Content-Type': 'application/x-www-form-urlencoded', 'Host': 'httpbin.org', 'User-Agent': 'python-requests/2.19.1' }, 'json': None, 'url': 'http://httpbin.org/post' }
⇒ Accessing the HTTP Request Object
⇐ requests.models.Response Objects
2018-08-14, 2464🔥, 0💬
Popular Posts:
How to use the urllib.request.Request object to build more complex HTTP request? The urllib.request....
How to use the "@(...)" expression in Azure API Policy? The "@(...)" expression in Azure API Policy ...
How To Get the Minimum or Maximum Value of an Array in PHP? If you want to get the minimum or maximu...
How to install .NET Framework in Visual Studio Community 2017? I have the Visual Studio Installer in...
How to read Atom validation errors at w3.org? If your Atom feed has errors, the Atom validator at w3...