This article introduces the HTTP protocol post request parameters in PHP, as follows:
The information in web development is basically all in the post and get request and response, get because of its URL-based intuitive, easy to understand, can post requests because of their information hidden, in the security, but also to developers to send a simulation of the trouble. In the next few posts, I will combine my own notes and understanding to explain in detail several ways in which PHP makes post requests, such as errors.
HTTP protocol information is an important part of web development, and understanding it can help us understand the BS interactions more deeply, as well as enable us to understand web development from a much lower level. HTTP protocol is a simple and flexible communication protocol, and remember that it is a stateless protocol, that is, it is a non-memory protocol, each interaction is separate.
We can use the Browser development tool (ie F12 Firefox firebug, etc.) of the "Network" Panel to view the HTTP header information.
Generally, HTTP header information is divided into three categories: request information, response information, and interactive information (one that is personally considered to be a request for information).
1, Request information:
When accessing a Web site, the client sends out the request information, which does not carry data, but simply touches the server, prompting the server to return the response information.
Its format is two parts: the request line and the message header.
A. Request Line: Method (Request methods) path (request in-station address) Http/version (Protocol/version information)
Common request methods are get/post/head/option and so on.
B. Message header:
Host (required): hostname and port number, port number defaults to 80
Accept: Expected receive content type (image/gif text/html */*)
Accept-encoding: Compression type expected to receive (gzip Deflat)
Accept-charset: Expected received character set (Utf-8)
Accept-language (ZH-CN)
Cookie: User's Cookie information
Connection: Connection Control
User-agent: Client Information
... ...
The following is a typical request header information:
GET index.php http/1.1
accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-encoding:gzip, deflate, SDCH
accept-language:zh-cn,zh;q=0.8
Cache-control:max-age=0
Connection:keep-alive
Cookie:sohuhometab=visit:2; iploc=cn1407; suv=1510312046259910
Host:www.sohu.com
If-modified-since:sat, Oct 12:45:22 GMT
Upgrade-insecure-requests:1
user-agent:mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/45.0.2454.99 safari/537.36
2, Response information
Server returns data
Response information is divided into three parts: status line message header response body
A. Status line: Http/version (Protocol/version information) Status Code status text (text description of the status code)
There are 5 types of status codes:
1XX: Indicates a temporary response and requires the requestor to continue operation
2XX: Indicates a successful response and the server successfully responded to the request
3XX: Indicates redirection, requires further action by requester
4XX: Indicates a client error and the server is not responding properly
5XX: Indicates a server-side error and the server is not responding properly
For details, refer to: HTTP status code in detail
B. Message header:
Server: Servers information
Content-encoding: Data compression format
Content-length: Data length
Content-type: Data type
Cache-control: Cache Control
Connection: Connection Control
Date: Day Information
Expires: Returning expiration information for data
Last-modified: Returns the last modified time
Set-cookie: Setting Cookie information for clients
... ...
C. Response body
That is, the page data that is returned is displayed as an HTML document in the page.
The following are common response messages
http/1.1 OK
Cache-control:no-cache
Connection:close
Content-encoding:gzip
content-length:6947
content-type:text/html; Charset=gbk
Date:sat, Oct 13:30:11 GMT
Expires:-1
Pragma:no-cache
Proxy-connection:keep-alive
server:nginx/1.2.5
SET-COOKIE:JSESSIONID=YIUUG4YEJHC1CDBZYDOXLCPN; path=/
3, interactive information
Is the request information containing the request data is common in the user upload file registration, etc.
It is divided into three parts: Request line message header request body
A. Same as request line for request information
B. Adding data about the request body on the basis of the request header
Content-type: Content type for uploading information
Content-length: Length of uploaded information
... ...
C. Request Body:
That is, the requested specific data string (NAME=XXX&PASSWORK=XXX), of course, for security reasons, the post information is sometimes encrypted encoding.
The following is a typical request message:
GET login.php http/1.1
Host:passport.sohu.com
Accept:text/html,application/xhtml+xml,application/xml
Accept-encoding:gzip, deflate
accept-language:zh-cn,zh;q=0.8
Cache-control:max-age=0
Connection:keep-alive
content-length:166
content-type:application/x-www-form-urlencoded
referer:http://mail.sohu.com/
user-agent:mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/45.0.2454.99 safari/537.36
Form Data
domain=sohu.com&callback=passport20008375022711697966_cb1446298206568&appid=1113&userid=fdffdf% 40sohu.com&password=a3f4384c2bc44fa909ffd0ecc5fa8eb9&persistentcookie=0
Understand what the browser is sending to the server, it is not difficult to disguise it as a server in other ways.
In the next section I will describe how PHP and JS handle the most basic URLs, as well as solving the GET Request section, and will also simulate the readiness to send a POST request.
If you think this blog is helpful to you, you can recommend or like, if you have any questions, you can also leave a comment, a discussion, thank you.