php通过CURL模拟get提交请求

方式一:

 $host = "http://jisunews.market.alicloudapi.com";
$path = "/news/get";
$method = "GET";
$appcode = "0c4e883bc09f4d0e926136ecb65fcafa";
$headers = array();
array_push($headers, "Authorization:APPCODE " . $appcode);
$querys = "channel=".$channel."&num=40&start=0";
$bodys = "";
$url = $host . $path . "?" . $querys; $ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($curl, CURLOPT_HEADER, true);
if ( == strpos("$".$host, "https://"))
{
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
$data = curl_exec($ch);
curl_close($ch);

方式二:

 $urlCity = urlencode($cityName);
$url = 'restapi.amap.com/v3/config/district?keywords='.$urlCity.'&subdistrict=0&key=ebf76716220ae651fd505d8eb9812c37';
//初始化一个 cURL 对象
$ch = curl_init();
//设置你需要抓取的URL
curl_setopt($ch, CURLOPT_URL, $url);
// 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
curl_setopt($ch, CURLOPT_RETURNTRANSFER, );
//是否获得跳转后的页面
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, );
$data = curl_exec($ch);
curl_close($ch);
上一篇:优化MySchool数据库设计总结


下一篇:Chrome 控制台 如何调试javascript