首先还是老生长谈,说说定义和作用,request模块是一个用于访问网络的模块,其实类似的模块还有很多,不在一一在这里解释。这么多的相似的模块为什么都说只有这个好用呢。因为他人性化。如果你学过urllib之类的模块的话,对比一下就很清楚了(文章url以题目实验吧的唯快不破)。
1, no matter what kind of script we all know the first to import the modules we need
2, since this module is to access the network module, we will give him a URL, send a GET request.
Because you are doing a CTF topic, so take the URL of the topic as an example
After sending, we will get this corresponding object re, which is the corresponding information we want. If you do not do any processing output, you will return the requested status code, if you want the content to appear, you need to add. text. Output in string format. Similarly, post delivery is the same.
3. Send request with parameters
Get request: When a GET request is sent, his parameter is the params passed to the keyword. Let's test it.
POST request: When sending a POST request, use data as the keyword parameter to pass the test
4. Get a field in the response header
We can use headers to test this.
Get all fields
Gets the specified field, for example, the title, I want to get the flag field
' Re.headers ' gets a dictionary, we want to get one, and we can get it in this form.
If we want to get the request header, we can re.request.headers it directly and test it.
5, the end of the article, send the topic of the CTF Python script, the topic is the experiment bar of the only fast not broken
Code
The basic usage of the requests module in the Python module is detailed