| Start |
|---|
Simple Post Will perform a simple HTTP POST operation. Posted data can be inmost formats, however key value pairs are most prevalent. Headers Headers can be viewed: An example response: Headers can also be prepared before post: Encoding Encoding can be set and viewed in much the same way: SSL Verification Requests by default validates SSL certificates of domains. This can be overridden: Redirection Any redirection will be followed (e.g. http to https) this can also be changed: If the post operation has been redirected, this value can be accessed: A full history of redirects can be viewed: |
Form Encoded Data To pass form encoded data with the post operation, data must be structured as dictionary and supplied as the data parameter. If the data does not want to be form encoded, simply pass a string, or integer to the data parameter. Supply the dictionary to the json parameter for Requests to format the data automatically: |
| File Upload With the Requests module,its is only necessary to provide a file handle as opposed to the contents retrieved with Filename, content_type and headers can also be set: Strings can also be sent as a file, as long they are supplied as the Multiple Files Multiple files can be supplied in much the same way as one file: |
| Responses Response codes can be viewed from a post operation: Returned Data Accessing data that is returned: Raw Responses In the instances where you need to access the underlying urllib3 response.HTTPResponse object, this can be done by the following: |
| Authentication Simple HTTP Authentication Simple HTTP Authentication can be achieved with the following: This is technically short hand for the following: HTTP Digest Authentication HTTP Digest Authentication is done in a very similar way, Requests provides a different object for this: Custom Authentication In some cases the built in authentication mechanisms may not be enough, imagine this example: A server is configured to accept authentication if the sender has the correct user-agent string, a certain header value and supplies the correct credentials through HTTP Basic Authentication. To achieve this a custom authentication class should be prepared, subclassing AuthBase, which is the base for Requests authentication implementations: This can then be utilized with the following code: |
| Proxies Each request POST operation can be configured to use network proxies HTTP/S Proxies HTTP Basic Authentication can be provided in this manner: SOCKS Proxies The use of socks proxies requires 3rd party dependencies |
Read Article
https://develop.horje.com/learn/1434/reference