Tools, FAQ, Tutorials:
Accessing the HTTP Request Object
How to access the HTTP request from the HTTP response object? I want to see what was actually delivered to the server.
✍: FYIcenter.com
To see what was actually delivered to the server,
you can take the "request" property of the response object:
>>> r = requests.post() >>> q = r.request # the requests.models.PreparedRequest object
"requests" module supports the following properties and functions on requests.models.PreparedRequest objects:
>>> r = requests.post() >>> q = r.request # the requests.models.PreparedRequest object >>> q.headers # represents the request headers as a dictionary >>> q.body # represents the request body as a strings >>> q.url # represents the url where this request was delivered >>> q.method # represents the HTTP method used >>> dir(q) ['__class__', ..., 'body', 'copy', 'deregister_hook', 'headers', 'hooks', 'method', 'path_url', 'prepare', 'prepare_auth', 'prepare_body', 'prepare_content_length', 'prepare_cookies', 'prepare_headers', 'prepare_hooks', 'prepare_method', 'prepare_url', 'register_hook', 'url' ]
Here is a Python example on how to see how form data was actually encoded in the HTTP request body:
>>> import requests
>>> form = {'userid':'fyi', 'password':'center'}
>>> r = requests.post('http://httpbin.org/post',data=form)
>>> q = r.request
>>> b = q.body
>>> print(b)
userid=fyi&password=center
⇒ Python Modules for MySQL Database
⇐ Sending an HTTP POST Request
2018-08-14, ∼2331🔥, 0💬
Popular Posts:
How to use the JSON to XML Conversion Tool at freeformatter.com? If you want to try the JSON to XML ...
What is Fabric CA (Certificate Authority)? Fabric CA (Certificate Authority) is a component of Hyper...
What is Fabric CA (Certificate Authority)? Fabric CA (Certificate Authority) is a component of Hyper...
How to validate the id_token signature received from Azure AD v2.0 authentication response? You can ...
What is EPUB 3.0 Metadata "dc:description" Element? EPUB 3.0 Metadata "dc:description" is an optiona...