Building an HTTP client with http.client
Python offers a series of modules designed to create an HTTP client. Python's main library modules are http.client
and urllib.request
. These modules have different capabilities, but they are useful for most of your web testing. We can also find module requests that provide some improvements over the standard library. To know more about these requests, visit https://docs.python.org/3/library/http.client.html.
So let's understand the http.client
module first. The http.client
module defines a class that implements the HTTPConnection
class. This class accepts a domain and a port as parameters. The domain is required, and the port is optional. An instance of this class represents a transaction with an HTTP server.
Let's demonstrate this with the help of an example in code. You can find the following code in the request_http_client.py
file inside the http.client
folder:
import http.client connection = http.client.HTTPConnection...