This article mainly introduces three kinds of methods that PHP sends POST request, use curl, file_get_content, fsocket to realize post submission data respectively, need friend can refer to under
Code as follows: Class request{ public static function post ($url, $post _data = ', $timeout = 5) {//curl & nbsp $ch = Curl_init (); curl_setopt ($ch, Curlopt_url, $url); curl_setopt ($ch, Curlopt_post, 1); if ($post _data!= ') { curl_setopt ($ch, Curlopt_postfields, $post _data); { curl_setopt ($ch, Curlopt_returntransfer, 1)   ; curl_setopt ($ch, Curlopt_connecttimeout, $timeout); curl_setopt ($ch, Curlopt_header, false); $file _contents = curl_exec ($ch); curl_close ($ch); return $file _contents; } public static function Post2 ($url, $data) {//file_get_content $postdata = http_build_query ( $data &N Bsp ); $opts = Array (' http ' => &NBSP ; Array ( &NB Sp ' method ' => ' POST ', &N Bsp ' header ' => ' content-type:application/x-www-form-urlencoded ', ' content ' => $postdata   ; ) &NBsp $context = Stream_context_create ($opts); $result = file_get_contents ($url, False, $context); return $result; } public static function Post3 ($host, $path, $query, $others = ') {//fs Ocket $post = "Post $path http/1.1rnhost: $hostrn"; $post. = "content-type:application/x-www-form-"; $post. = "Urlencodedrn${others}"; $post. = "User-agent:mozilla 4.0rncontent-length:"; $post. =strlen ($query). Rnconnection:closernrn$query "; $h =fsockopen ($host, 80); fwrite ($h, $post); for ($a =0, $r = ';! $a;) { &NBsp $b =fread ($h, 8192); $r. = $b; $a = (($b = = ")? 1:0); , fclose ($h); return $r; }}