php 模拟浏览器get和post提交处理

文件夹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>\n";
foreach ($info as $name=>$key){
echo "$name===$key<br>\n";
}

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>\n";
}
?>

上一篇:xpath元素定位方法


下一篇:ELK日志分析系统