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, ∼2963🔥, 0💬
Popular Posts:
How To Copy Array Values to a List of Variables in PHP? If you want copy all values of an array to a...
How To Break a File Path Name into Parts in PHP? If you have a file name, and want to get different ...
How to add request query string Parameters to my Azure API operation 2017 version to make it more us...
How To Truncate an Array in PHP? If you want to remove a chunk of values from an array, you can use ...
What properties and functions are supported on requests.models.Response objects? "requests" module s...