Today the company has colleagues let me tell him a talk about HTTP. Then I wrote a sample code, which if you do not understand. Then I can't do it.
1<?PHP2 3 //here the server takes Apache for example. Nginx.iis. They're actually dealing with the same way .4 //Declaration of HTTP-linked packets Note the last number is two. This is to tell Apache. The end of the packet, if there are no two replacement numbers. Apache will assume that the data you requested is not over.5 //Get here. The description is accessed by the GET method. If it is post, it is accessed by post. The post data will be stitched after the two change number6 //Here get followed by/is the path to access: If you need access to aaaa.php then add aaaa.php to the/back .7 //host Description I was telling Apache that I was going to visit that domain.8 //Of course there are other properties. Other properties Baidu a bit basic can be ...9 $http= <<<Pcntl_enfileTenget/http/1.1 OneHost:www.ip138.com A - - Pcntl_enfile; the - - //establish links with Www.ip186.com's 80 port and return linked resources - $sock=Pfsockopen("Www.ip138.com", 80); + - //sending HTTP packets to ip138 's linked resources equals to ip138 . + fwrite($sock,$http); A //after talking to the server. What to do inside the server. HTTP is not required. And then the answer is the reply. at //after sending the packet. Reads the data returned by the linked resource of ip138. The length of the read data is 99999. is equal to listen to ip138 reply 99,999 words - $pack=fread($sock, 99999); - - //divides the data that is read into the head. and topic content The head is the word to the browser. Topic content is HTML code - //For example, set the cookie is in the head ... - //Here is also the use of the two carriage return to distinguish the number of ... in List($header,$html) =Explode("\r\n\r\n",$pack, 2); - //print data for the browser to process to Print_r($header); + - //Print the HTML code. the Print_r($html);
HTTP protocol Description