HTTP requests and corresponding as well as PHP implementation simulation, Curl extension use to simulate access

Source: Internet
Author: User
Tags php script

1. Handle different picture formats for image processing the common class is compatible with the processing of multiple image types.

As long as you use different types of pictures with different imagecreatefrom types can be implemented.

"Focus!!! "PHP Implementation of network Programming" 2.HTTP Request Protocol "HTTP authoritative guide has been seen, but has not been deeply aware of" http used to standardize the B/s architecture, browser and server information exchange between the rules. "Hypertext Transfer Protocol (Hyper-text markup Language and data)"

TCP connection between browser and server "Connection section needs to be noted: Three handshake has not been said. The resource problem that the persistent connection itself occupies (persistent connection ensures smooth HTTP transmission) "

Request Message "Request" (1) Request Line "The first line of the requested data, there are three information: how to request (HTTP request: such as Get), request URL, protocol version (http/1.1)" (2) Request Header " Send some status code in the request: Browser information, cookies, etc. "" need to use a blank line to end "(3) Request Body" Post mode to transfer data when there is a subject "

So-called network programming is the use of language to simulate HTTP requests and results, to achieve the effect we need.

3.php analog HTTP requests after you know the HTTP request message, use PHP to generate such a request for impersonation. The "Focus" crawler is doing the same. Request and response results by script "PHP Analog GET Request (1) Connect to target server first" use PHP functions: Fsocketopen to establish a socket or Internet connection. Need to use IP and port for unique identification "(2) after using this function to connect to the server, return a resource" stream stream "has a clearer understanding of resources and connections. "The key is the connection, and the connection consumes server resources need to learn from the server" (3) after the connection, using the requested message to simulate the "PHP generated message Information" (4) Send the request "with the newly created stream data channel, and Fwrite write to the target server"

This enables PHP to simulate an HTTP request. "And the PHP script requires a browser request to run, so the script used to simulate HTTP requests is equivalent to making a layer of middle tier"

PHP to receive response results: Use Fgets to accept response data "one line of receipt." It is also the stream "" that uses loops to receive fgets results: Full text (using feof to determine if the end of the data stream) "

4.HTTP Response message Response information: "Response Line": protocol version, Status code, status message "Status code and status message are corresponding: used to indicate response result" status code: 200: State normal 300: Request redirected 400:not found 500:server internal Error "Response header" : The server needs to tell the browser that some of the information "such as file type, etc." is a multiline representation, and also requires a blank line to indicate the end of the response header "corresponding principal": The file used to display in the browser is the corresponding principal.

"The need for a newline in an HTTP message requires the use of a line break in any system \ r \ n"

5.php operation response results using the header function to manipulate the response header "Cookie in response results can also be set" "The Essence of the download is to save (rather than display) the data that was originally transferred from the server (instead of being displayed): Managed by the response header (header function). (Can be downloaded by the header for the type of file and whether it is opened) "use Echo to manipulate the response body" This does not require much to say, direct output can be processed "

6.php Analog POST Request "is the operation request body!! "Use PHP to simulate a form submission. The form of a key-value pair to form the request body.

Only in the information in HTTP, the difference between the empty lines, and the HTTP mechanism itself does not matter. "It just needs to indicate the necessary information in the requesting body: principal type, body length, etc." Finally, use fwrite to send the data.

"Focus" 7.curl "is designed to simulate HTTP requests in a way that implements various requests" is a standalone tool: is an extension "" Php_curl.dll "curl provides a number of functions to implement HTTP request simulation work

A complete set of functions needs to be noted. "Because now the request basically requires a cookie and session, so curl also needs to carry these session information for the mock request"

Because there is such a simulation process, we use verification codes to prevent brute force cracking. "To determine the user's password by traversing the way"

8.

HTTP requests and corresponding as well as PHP implementation simulation, Curl extension use to simulate access

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.