Tools, FAQ, Tutorials:
Sending an HTTP Request with 'requests'
How to send an HTTP request? I have the "requests" module installed now.
✍: FYIcenter.com
The "requests" module provides 6 static functions to support 6 HTTP request types:
>>> r = requests.get(url)
>>> r = requests.post(url, data = {'key':'value'})
>>> r = requests.put(url, data = {'key':'value'})
>>> r = requests.delete(url)
>>> r = requests.head(url)
>>> r = requests.options(url)
All 6 functions return a requests.models.Response object.
You can convert the body of the Response object to a "dict" object using the instance function json():
>>> j = r.json()
Here is a Python example on how to send a GET request and print the response body in JSON format:
>>> import requests
>>> r = requests.get('http://httpbin.org/get')
>>> j = r.json()
>>> print(j)
{'args': {},
'headers': {'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate',
'Connection': 'close',
'Host': 'httpbin.org',
'User-Agent': 'python-requests/2.19.1'
},
'url': 'http://httpbin.org/get'
}
⇒ requests.models.Response Objects
⇐ Installing 'requests' Module
2018-09-01, ∼2162🔥, 0💬
Popular Posts:
What Happens If One Row Has Missing Columns? What happens if one row has missing columns? Most brows...
Where Is the Submitted Form Data Stored in PHP? When a user submit a form on your Web server, user e...
FYIcenter.com Online Tools: FYIcenter JSON Validator and Formatter FYIcenter JSON to XML Converter F...
How to use "xml-to-json" Azure API Policy Statement? The "xml-to-json" Policy Statement allows you t...
How To Read a File in Binary Mode in PHP? If you have a file that stores binary data, like an execut...