developer tip

cURL 오류 (7) 해결 방법 : 호스트에 연결할 수 없습니까?

copycodes 2021. 1. 8. 08:30
반응형

cURL 오류 (7) 해결 방법 : 호스트에 연결할 수 없습니까?


cUrl (php)을 사용하여 xml 형식의 웹 서비스에 항목 코드를 보냅니다. localhost에서 올바른 응답을 얻었지만 언제 서버에 표시됩니까?

cURL 오류 (7) : 호스트에 연결할 수 없습니다.

그리고 여기에 내 코드가 있습니다.

function xml_post($post_xml, $url)
{
    $user_agent = $_SERVER['HTTP_USER_AGENT'];

    $ch = curl_init();    // initialize curl handle
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_FAILONERROR, 1);          
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 50); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_xml); 
    curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
//  curl_setopt($ch, CURLOPT_PORT, $port);          

    $data = curl_exec($ch);
    $curl_errno = curl_errno($ch);
    $curl_error = curl_error($ch);
    if ($curl_errno > 0) {
            echo "cURL Error ($curl_errno): $curl_error\n";
    } else {
            echo "Data received\n";
    }
    curl_close($ch);

    echo $data;
}

항목 코드를 집계에 보내고 세부 정보를 가져옵니다. php 4+ 및 php5 + 버전을 모두 사용해 보았지만 어떤 솔루션도 작동하지 않습니다.


CURL 오류 코드 7 (CURLE_COULDNT_CONNECT)

매우 명시 적입니다 ... Failed to connect() to host or proxy.

다음 코드는 모든 시스템에서 작동합니다.

$ch = curl_init("http://google.com");    // initialize curl handle
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
print($data);

Google 페이지가 보이지 않으면 .. 또는 문제 your URL is wrongfirewall있거나 restriction문제가 있습니다.


"CURL ERROR 7 Failed to connect to Permission denied"오류가 발생합니다. 어떤 이유로 든 일부 방화벽이나 이와 유사한 것에 의해 curl 요청이 차단 될 때 발생합니다.

curl 요청이 표준 포트가 아닌 경우이 문제가 발생합니다.

예를 들어 포트 1234에있는 일부 URL로 컬을 수행하면 포트 80이있는 URL이 쉽게 결과를 제공하는이 문제에 직면하게됩니다.

가장 일반적으로이 오류는 CentOS 및 'SElinux'가 설치된 다른 OS에서 발생했습니다.

허용하도록 'SElinux'를 비활성화하거나 변경해야합니다.

이것 좀 봐

http://www.akashif.co.uk/php/curl-error-7-failed-to-connect-to-permission-denied

도움이 되었기를 바랍니다


제 경우에는 cURL Error (7): ... Operation Timed Out. 근무중인 회사의 네트워크 연결을 사용하고 있습니다. 환경 변수를 만들어야했습니다. 다음은 나를 위해 일했습니다.

Linux 터미널에서 :

$ export https_proxy=yourProxy:80
$ export http_proxy=yourProxy:80  

Windows에서는 Windows 방식으로 (동일한) 환경 변수를 만들었습니다.

도움이 되었기를 바랍니다.

문안 인사!


Are you able to hit that URL by browser or by PHP script? The error shown is that you could not connect. So first confirm that the URL is accessible.


In PHP, If your network under proxy. You should set the proxy URL and port

curl_setopt($ch, CURLOPT_PROXY, "http://url.com"); //your proxy url
curl_setopt($ch, CURLOPT_PROXYPORT, "80"); // your proxy port number

This is solves my problem


Check if port 80 and 443 are blocked. or enter - IP graph.facebook.com and enter it in etc/hosts file


This issue can also be caused by making curl calls to https when it is not configured on the remote device. Calling over http can resolve this problem in these situations, at least until you configure ssl on the remote.


In my case, the problem was caused by the hosting provider I was using blocking http packets addressed to their IP block that originated from within their IP block. Un-frickin-believable!!!


you can also get this if you are trying to hit the same URL with multiple HTTP request at the same time.Many curl requests wont be able to connect and so return with error

ReferenceURL : https://stackoverflow.com/questions/9922562/how-to-resolve-curl-error-7-couldnt-connect-to-host

반응형