php curl 跨域请求例子
public function getresapi($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result=curl_exec($ch); curl_close($ch); return($result);}$url = 'http://xxxx.com/index.php?r=api/xxx&from='.$starttime.'&to='.$endtime.'&url='.$url;$result = $getresapi($url);
例子二
curl.php
11,"cyid"=>22,"startday"=>33,"endday"=>44,"page"=>55,"limit"=>66);$url = 'http://test.xxx.com/curl_dome.php';//请求的url地址$ch = curl_init();curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_POSTFIELDS, $arrPostInfo);$response = curl_exec($ch);curl_close($ch);$result = json_decode($response,true);var_dump($result);
curl_dome.php
11,"cyid"=>22,"startday"=>33,"endday"=>44,"page"=>55,"limit"=>66);echo json_encode($arrPostInfo);