<?php
header("Content-type: text/html; charset=utf-8"); //解决中文乱码
/**
* 模拟post进行url请求
* @param string $url
* @param array $post_data
*/
function request_post($url = '', $post_data = array()) {
if (empty($url) || empty($post_data)) {
return false;
}
$postUrl = $url;
$curlPost = $post_data;
$ch = curl_init();//初始化curl
curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch, CURLOPT_ENCODING, "");//解压
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Encoding: gzip, deflate,flate'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证证书下同
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //不验证证书下同
$data = curl_exec($ch);//运行curl
curl_close($ch);
//$res=json_decode($data,true);
return $data;
}
function testAction(){
$url = 'https://am.22.cn/ajax/taoym/default.ashx?t=0.5844175927806412';
$post_data['atype'] = '4';
$post_data['keyword'] = 'haha';
//$post_data = array();
$res = request_post($url, $post_data);
echo $res;
}
testAction();
?>