curl模拟post请求

<?php
$post_data = array(
'hello=你好',
'world=世界',
);
$post_data = implode('&',$post_data);
$url='http://localhost.test.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//设定为不验证证书和host
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);//设定为不验证host
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);//传递一个作为HTTP “POST”操作的所有数据的字符串。
ob_start();
curl_exec($ch);
$result = ob_get_contents() ;
ob_end_clean();

echo $result;

?>

 

posted @ 2013-08-29 22:13  茗迹周  阅读(295)  评论(0编辑  收藏  举报