Understanding of the request module of the python module

First of all, let’s talk about the definition and function. The request module is a module used to access the network. In fact, there are many similar modules, which will not be explained here one by one. Why do so many similar modules say that only this one is easy to use? Because of his humanization. If you have learned modules such as urllib, the comparison will be very clear

1. No matter what kind of script we write, we know that we need to import the modules we need first.

 

2. Since this module is a module that accesses the network, we pass it a url and send a get request.

Because I am doing a ctf problem, I will take the url of the title as an example.

After sending, we will get the corresponding object re, which is the corresponding information we want. Here, if you do not do any processing output, the status code of the request will be returned. If you want the content to appear, you need to add .text. Output in string format. The same is true for post delivery.

3. Send a request with parameters

get request: When sending a get request, its parameters are passed as the keyword params. Let's test it

Post request: When sending a post request, it is passed with data as a keyword parameter, test it

4. Get a field in the response header

We can use headers to test this

get all fields

Get the specified field, such as this topic, I want to get the FLAG field

're.headers' gets a dictionary, if we want to get a certain one, we can get it in this form.

If we want to get the request header, we can directly re.request.headers and test it

At the end of the article, I will send a python script for the ctf topic. The topic is the experiment.

code

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324603217&siteId=291194637