The example in this article describes how PHP implements a simulated POST request. Share to everyone for your reference. as follows:
Class request{public static function post ($url, $post _data = ', $timeout = 5) {//curl $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;
The public static function Post2 ($url, $data =array ()) {//file_get_content $postdata = http_build_query ($data); $opts = Array (' http ' => Array (' method ' => ' POST ', ' header ' => ' content-type:application/
x-www-form-urlencoded ', ' content ' => $postdata));
$context = Stream_context_create ($opts);
$result = File_get_contents ($url, False, $context);
return $result; The public static function Post3 ($host, $path, $query, $others = ') {//FSOCKet $post = "Post $path http/1.1\r\nhost: $host \ r \ n";
$post. = "content-type:application/x-www-form-";
$post. = "Urlencoded\r\n${others}";
$post. = "User-agent:mozilla 4.0\r\ncontent-length:"; $post. =strlen ($query). "
\r\nconnection:close\r\n\r\n$query ";
$h =fsockopen ($host, 80);
Fwrite ($h, $post); For ($a =0, $r = ';!
$a;) {$b =fread ($h, 8192);
$r. = $b;
$a = (($b = = ")? 1:0);
} fclose ($h);
return $r;
}} $url = ' http://******/con/inter.php ';
$data =request::p ost ($url, Array (' API ' => ' tag_list '));
$data 2=request::p ost2 ($url, Array (' API ' => ' tag_list '));
Echo $data;
I hope this article will help you with your PHP programming.