php 模拟 post 请求的方法总结。主要有两种办法,通过 fsocket 和通过 curl,下面就简单的举两个案例说明一下 php 如何使用这两种方法模拟 post 请求。
(1)php 通过 fsocket 模拟 post 提交请求
";
    }
}
使用方法如下(注意$url这个参数必须是域名,不可以是localhost这种形式的url):
$purl="http://www.maopiaopiao.com/post.php"; echo "以下是POST方式的响应内容: "; sock_post($purl,"name=php程序员教程网&url=http://www.maopiaopiao.com/");
(2)php 通过 curl 模拟 post 提交请求
'justcoding',
    'fname'=>'phplover',
    'title'=>'myapi',
    'email'=>'123456789@qq.com',
    'phone'=>'13611975347'
);
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields);
ob_start();
curl_exec($ch);
$result=ob_get_contents();
ob_end_clean();
echo $result;
curl_close($ch);