Invented by Tim Berners-Lee at CERN in the years 1989–1991, HTTP (Hypertext Transfer Protocol) is the underlying communication protocol of World Wide Web. HTTP functions as a request response protocol in the client–server computing model. HTTP standards are developed by the Internet Engineering Task Force (IETF) and the World Wide Web Consortium (W3C), culminating in the publication of a series of Requests for Comments (RFCs). HTTP has four versions — HTTP/0.9, HTTP/1.0, HTTP/1.1, and HTTP/2.0. Today the version in common use is HTTP/1.1 and the future will be HTTP/2.0.
HTTP- Hyper Text Transfer Protocol is the application level protocol to communicate between web servers and web browsers. It provides the means for web browser to request content from a web server using the GET method, and sending content to a web server using POST method. Other methods such as OPTIONS, PUT and DELETE are also specified in the HTTP protocol.
import requests
payload = {'q': 'sri+lanka'}
r = requests.get('<https://www.google.com/search?'>, params=payload)
print(r.url)
print (r.text)
This code makes a request to the Google search engine with a specific query parameter. Here's a breakdown of what the code does:
requests
library, which is a popular Python library for making HTTP requests.payload
with a single key-value pair: 'q': 'sri+lanka'
. The key 'q'
represents the query parameter, and the value 'sri+lanka'
is the search query itself. The +
sign is used to represent spaces in the URL.'<https://www.google.com/search?'
> using requests.get()
. The params
parameter is used to pass the payload
dictionary, which will be appended to the URL as query parameters.requests.get()
method to the variable r
.r.url
. This will display the complete URL with the query parameters included.r.text
. This will display the HTML content of the Google search results page.In summary, this code sends a search query for "sri lanka" to Google and prints the URL of the request as well as the HTML content of the search results page.
Get request must be a string, which is framed as the following example: