时间:2021-07-01 10:21:17 帮助过:6人阅读
CURLE_COULDNT_RESOLVE_HOST (6)
Couldn't resolve host. The given remote host was not resolved.
原来程序是可以正常获取接口返回数据的,这个情况是突然出现的,不知道是不是api限制了调用?目前还不知道具体解决办法,大家如果有遇到相同情况,可以分享一下解决办法,谢谢。
PS:直接在浏览器访问接口url是可以获取得到数据的。
curl代码:
public function getApiDataWithCurl($params = array()){
$doc = array(
'result'=>0,
'content'=>'',
);
if(!isset($params['feed_id'])) return $doc;
if(!isset($params['apikey'])) return $doc;
$getUrl = $this->apiUrl.'?';
foreach($params as $k => $v){
if($v != ''){
$getUrl .=$k.'='.$v.'&';
}
}
$getUrl = substr($getUrl,0,strlen($getUrl)-1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$getUrl);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
$response_content = curl_exec($ch);
$error_code = curl_errno($ch);
$curl_info = curl_getinfo($ch);
curl_close($ch);
$response_content = simplexml_load_string($response_content);
$json = json_encode($response_content);
$response_content = json_decode($json,TRUE);
if($error_code || (!$response_content && $curl_info['http_code']!=200)){
return 'CURL ERROR: error code '.$error_code;
}else{
$doc = array(
'result'=>1,
'content'=>$response_content,
);
return $doc;
}
}
我在使用curl调取接口获得数据时,出现了curl_errno()返回错误码 '6' 的情况,百度了一下
CURLE_COULDNT_RESOLVE_HOST (6)
Couldn't resolve host. The given remote host was not resolved.
原来程序是可以正常获取接口返回数据的,这个情况是突然出现的,不知道是不是api限制了调用?目前还不知道具体解决办法,大家如果有遇到相同情况,可以分享一下解决办法,谢谢。
PS:直接在浏览器访问接口url是可以获取得到数据的。
curl代码:
public function getApiDataWithCurl($params = array()){
$doc = array(
'result'=>0,
'content'=>'',
);
if(!isset($params['feed_id'])) return $doc;
if(!isset($params['apikey'])) return $doc;
$getUrl = $this->apiUrl.'?';
foreach($params as $k => $v){
if($v != ''){
$getUrl .=$k.'='.$v.'&';
}
}
$getUrl = substr($getUrl,0,strlen($getUrl)-1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$getUrl);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
$response_content = curl_exec($ch);
$error_code = curl_errno($ch);
$curl_info = curl_getinfo($ch);
curl_close($ch);
$response_content = simplexml_load_string($response_content);
$json = json_encode($response_content);
$response_content = json_decode($json,TRUE);
if($error_code || (!$response_content && $curl_info['http_code']!=200)){
return 'CURL ERROR: error code '.$error_code;
}else{
$doc = array(
'result'=>1,
'content'=>$response_content,
);
return $doc;
}
}
这是无法解析域名的问题,你试下把url打出来,看看能否ping通
curl可以贴一下么
看你这个是GET方式传值请求吧!你直接使用file_get_content
试试呢!是不是对方设置白名单了