<?php
/**
* PHP中CURL模拟Post提交
* by www.jb200.com
*/
$url = 'http://website/a.php';
$fields = array(
'UserName'=>urlencode('a'),
'PWD'=>urlencode('b') ,
'AppReturn'=>urlencode('c') ,
'AppSQL'=>urlencode('d') ,
);
$fields_string = http_build_query($fields);
$ch = curl_init() ;
curl_setopt($ch, CURLOPT_URL,$url) ; //设置要采集的URL
curl_setopt($ch, CURLOPT_POST,1) ; //设置形式为POST
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string) ;//设置Post参数
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); //用字符串打印出来。
$re = curl_exec($ch);//(如果没有设置CURLOPT_RETURNTRANSFER为1,那么将会执行并获取HTML文档内容,如:1;否则将会将结果返回,而不是执行)
print_r($re);
$info = curl_getinfo($ch);//请求的有关信息
print_r($info);
$data = array ('UserName' => 'bar');
$data = http_build_query($data);
$opts = array (
'http' => array (
'method' => 'POST',
'header'=> "Content-type: application/x-www-form-urlencodedrn" .
"Content-Length: " . strlen($data) . "rn",
'content' => $data
),
);
$context = stream_context_create($opts);
$html =
file_get_contents($url, false, $context);
echo $html;
var_dump($http_response_header);