我正在使用curl从托管在Web上不同位置的不同Web服务中获取数据。我正在尝试将数据获取到我的本地主机。
$token1="SOMETOKENXX";
$mobileNumber= $_POST['number'];
$postData = array(
'mobile' =>$mobileNumber
);
$service_url ='http://api.hashtagloyalty.in/merchants/users/users_profile';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $service_url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_PORT, 8080);
curl_setopt($curl, CURLOPT_USERAGENT , "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17");
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($postData));
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json','Authorization:'.$token1));
$curl_response = curl_exec($curl);
// echo($curl_response);
if ($curl_response === false)
{
$info = curl_getinfo($curl);
die('error occured during curl exec. Additioanl info: ' . var_export($info));
}else{
echo "TRUE";
}
curl_close($curl);
我无法在xampp localhost上获取结果,但在GoDaddy实时服务器上工作。
我正在研究最新版本的xampp 7.2.6和Windows 10 OS
我正在访问8080端口上的本地主机,这意味着我的localhots网址是localhost:8080。
我怎么知道是否有什么阻止了我的请求? 没有结果,结果为空。
请帮助
error
array ( 'url' => 'http://api.hashtagloyalty.in/merchants/users/users_profile', 'content_type' => NULL, 'http_code' => 0, 'header_size' => 0, 'request_size' => 0, 'filetime' => -1, 'ssl_verify_result' => 0, 'redirect_count' => 0, 'total_time' => 20.204, 'namelookup_time' => 1.0E-6, 'connect_time' => 0.0, 'pretransfer_time' => 0.0, 'size_upload' => 0.0, 'size_download' => 0.0, 'speed_download' => 0.0, 'speed_upload' => 0.0, 'download_content_length' => -1.0, 'upload_content_length' => -1.0, 'starttransfer_time' => 0.0, 'redirect_time' => 0.0, 'redirect_url' => '', 'primary_ip' => '', 'certinfo' => array ( ), 'primary_port' => 0, 'local_ip' => '', 'local_port' => 0, )error occured during curl exec. Additioanl info:
答案 0 :(得分:0)
可能是防火墙问题
cURL使用端口1080可能未打开
多个修复程序:
在防火墙/路由器中打开端口1080
或
为cURL指定一个(有效的)端口
curl_setopt($curl, CURLOPT_PORT, PortYouWantHere)
答案 1 :(得分:0)
curl
无法正常工作,因为我的组织的代理阻止了该请求。因此,我添加了以下代码,它的工作方式就像魅力:)
curl_setopt($ch, CURLOPT_PROXY, $proxyhostandpass);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyusernamepass);