当前示例是展示curl请求raw数据的方法,如下:
$headers = [
'Content-Type:application/json',
'App-Key:'.$key,
'App-Sign:'.$result,
'X-AjaxPro-Method:ShowList',
'User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36'
];
$callBack = [
"mobile" => 111,
"content" => "测试"
];
$postUrl= 'http://www.baidu.com/';
$jsonContent = json_encode($callBack);
//用法
$result = http_post_json($postUrl, $headers, $jsonContent);
/* @param $postUrl
* @param $headers
* @param $jsonContent
* @return mixed
*/
function http_post_json($postUrl, $headers, $jsonContent)
{
$ch = curl_init();//初始化curl
curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);//执行命令
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonContent);
$data = curl_exec($ch);//运行curl
curl_close($ch);
$data = json_decode($data,true);
return $data;
}