I have tried it, it is very useful.
/** * Constructs an AJAX request that does not support HTTPS * / functionajax_http_request($url, $data = array(), $type = "Post", $params = array(), $accept = "", $ua =
"",
$referer =
"",
$file = False)
{$http= Strtolower (substr ($url,0,7));$type= Strtolower ($type);$url _params= Parse_url ($url);if(!$url _params) {Echo' URL error ';returnfalse; }$hostip= GetHostByName ($url _params[' Host ']);if(!$hostip) {Echo' Unable to access server ';returnfalse; }$fp= Fsockopen ($url _params[' Host '], the,$errno,$errstr, -);if(!$fp) {Echo"$errstr ($errno)
";returnfalse; }$query _string= Http_build_query ($data);if($type==' Post ') {$out=' POST '.$url _params[' path ']."http/1.1\r\n"; }Else{if(Strpos ($url,'?') !=false) {$path=$url.' & '.$query _string; }Else{$path=$url.'?'.$query _string; }$out=' GET '.$path.' http/1.1 '."\ r \ n"; }$out.=' Host: '.$url _params[' Host ']."\ r \ n";$out.="connection:close\r\n";if($type==' Post ') {if($file) {$out.= ("content-type:multipart/form-data\r\n");//Ajax file upload temporarily does not have this feature}Else{$out.= ("content-type:application/x-www-form-urlencoded\r\n"); }$out.= ("Content-length:". strlen ($query _string)."\ r \ n"); }if(isset($ua)) {$out.= (' user-agent: '.$ua."\ r \ n"); }Else{$out.= ("user-agent:mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) applewebkit/537.36 (khtml, like Gecko) chrome/41.0.2272.118 safari/537.36\r\n "); }if(isset($referer)) {$out.= (' referer:http://'.$url _params[' Host '].'/'.$referer."\ r \ n"); }Else{$out.= (' referer:http://'.$url _params[' Host ']."\ r \ n"); }$out.= ("origin:http://".$url _params[' Host ']."\ r \ n");$out.= ("x-requested-with:xmlhttprequest\r\n");$out.= ("Accept:application/json, Text/javascript, */*\r\n");$out.="accept-language:zh-cn,zh;q=0.8,en;q=0.6\r\n\r\n";if($type==' Post ') {//Next is the message body information$out.=$query _string; } fwrite ($fp,$out);$output=""; while(!feof ($fp)) {$output. = Fgets ($fp, -); } fclose ($fp);$result= Explode ("\r\n\r\n",$output);$result= Explode ("\ r \ n",$result[1]); Array_pop ($result); Array_shift ($result);returnImplode ("\ r \ n",$result);}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The above describes the use of PHP to simulate the source code of AJAX requests, including aspects of the content, I hope to be interested in PHP tutorial friends helpful.