php curl模拟post请求小实例
使用php curl模拟post请求的小例子,提供大家学习一下
本机:
<div class="codetitle"><a style="CURSOR: pointer" data="34666" class="copybut" id="copybut34666" onclick="doCopy('code34666')"> 代码如下:
<div class="codebody" id="code34666">
<?PHP
$uri = "http://www.a.com/test.PHP";//这里换成你服务器的地址
// 参数数组
$data = array (
'name' => 'tanteng'
// 'password' => 'password'
);$ch = curl_init ();
// print_r($ch);
curl_setopt ( $ch,CURLOPT_URL,$uri );
curl_setopt ( $ch,CURLOPT_POST,1 );
curl_setopt ( $ch,CURLOPT_HEADER,0 );
curl_setopt ( $ch,CURLOPT_RETURNTRANSFER,CURLOPT_POSTFIELDS,$data );
$return = curl_exec ( $ch );
curl_close ( $ch );print_r($return);