Teach you how to simulate HTTP requests with Python (get,post)

Source: Internet
Author: User

What is the use of simulating HTTP requests?

All we need to use the Internet now: Most of the features in the Software App app website are working through the HTTP protocol.

What is the HTTP protocol?

HTTP protocol, Hypertext Transfer Protocol (Http,hypertext Transfer Protocol) is one of the most widely used network protocols on the Internet.

Need to know more about HTTP please search by yourself, this article briefly talk about the HTTP request process

The request is sent by the client, the request is a piece of text (Request message), the server gets the parameters in the request, is processed by the backend, and then performs the corresponding function.

The service side returns a paragraph of text (the response message, there is no return information), the client gets the information in the message, make a corresponding display.

We use an app user registration as an example

When the user needs to register, fill in the completion of their mobile phone number (no request occurred at this time)

Click the Get Captcha button, at which point the client (APP) sends a request message to an address containing the phone number you filled in:

The request contains a phone parameter with the value of your phone number

Then the server receives your mobile phone number, executes the SMS Verification code function, and then sends the response message to the client:

The response message contains a number of parameters, the server to get these parameters, to make a corresponding display (such as display: Message sent successfully)

The above completes an HTTP interaction,

According to the above example, we can pass the analog request message, pass on someone's mobile number, send the request multiple times, realize the harassment of the mobile phone number owner (SMS Bomber function)

How do I simulate the request?

First we need to install the requests module

Installation commands

PIP Install requests

First analyze the request

The request method in the figure is post, so we need to use the Requests.post (url,headers,data) function, which requires three parameters, as shown in the picture

Fill

In a Python program

Import Requests # Import Module
Url= "http://bbs.zcbxw.com/mag/xxx/xx/..." #自行补全
headers={"Host": "bbs.zcbxw.com", "xxx": "xxx", "xx": "XX"} self-complement
Data= "phone= mobile phone number &country_code=86"
Requests.post (Url=url,headers=headers,data=data)
#将headers与url按照图中所示补全, the other code does not change, runs, completes a request

Teaches you how to simulate HTTP requests with Python (get,post)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.