PHP curl error: curl__errno() returns error code 6

WBOY
Release: 2023-03-02 08:30:02
Original
6266 people have browsed it

When I used curl to call the interface to obtain data, curl_errno() returned the error code '6'. Baidu looked it up

<code>CURLE_COULDNT_RESOLVE_HOST (6)
Couldn't resolve host. The given remote host was not resolved.</code>
Copy after login
Copy after login

It turns out that the program can normally obtain the data returned by the interface. This situation occurred suddenly. I wonder if the API restricts the call? I don’t know the specific solution yet. If you encounter the same situation, you can share the solution. Thank you.
PS: The data can be obtained directly by accessing the interface url in the browser.
curl code:

<code>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;
        }
    }</code>
Copy after login
Copy after login

Reply content:

When I used curl to call the interface to obtain data, curl_errno() returned the error code '6'. Baidu looked it up

<code>CURLE_COULDNT_RESOLVE_HOST (6)
Couldn't resolve host. The given remote host was not resolved.</code>
Copy after login
Copy after login

It turns out that the program can normally obtain the data returned by the interface. This situation occurred suddenly. I wonder if the API restricts the call? I don’t know the specific solution yet. If you encounter the same situation, you can share the solution. Thank you.
PS: The data can be obtained directly by accessing the interface url in the browser.
curl code:

<code>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;
        }
    }</code>
Copy after login
Copy after login

This is a problem of being unable to resolve the domain name. Try typing out the URL and see if you can ping it

Can you post curl

Look, this is a GET value request! You can try using file_get_content directly! Has the other party set up a whitelist?

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template