文件夹test下index.php
<?php
header("Content-Type: text/html;charset=gb2312");
function cUrlGet($url='http://www.ji-meng.com'){
//初始化
$ch = curl_init();
//设置选项,包括URL
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
//执行并获取HTML文档内容
$output = curl_exec($ch);
//释放curl句柄
curl_close($ch);
return $output;
}
function cUrlPost($url='http://www.ji-meng.com',$post_data=array()){
//$url = "http://localhost/web_services.php";
//$post_data = array ("username" => "bob","key" => "12345");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// post数据
curl_setopt($ch, CURLOPT_POST, 1);
// post的变量
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output[] = curl_exec($ch);
$output[]=curl_getinfo($ch);
curl_close($ch);
return $output;
}
list($output,$info)=cUrlPost('http://localhost/test/post.php',array('username1'=>'boby','key'=>'123456'));
echo $output;
echo "<br>
";
foreach ($info as $name=>$key){
echo "$name===$key<br>
";
}
test文件夹下post.php文件
<?php
header("Content-Type: text/html;charset=gb2312");
echo "good! your post:<br>";
foreach ($_POST as $item=>$key){
echo "'$item'=".$key."<br>
";
}
?>