cURL导致404错误

时间:2013-10-18 16:13:29

标签: php curl http-status-code-404

我面临着一个非常令人惊讶的cURL请求行为。 该脚本已运行好几个月,但发生了一些事情,代码不再有效。

$url = "http://domain.net:443/connexion.php";
$ch = curl_init();
$f = fopen('request.txt', 'w');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PORT , 443);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_STDERR, $f);
$data = curl_exec($ch);

if(!curl_errno($ch)){ 
    $info = curl_getinfo($ch); 
    echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url']; 
} else { 
    echo 'Curl error: ' . curl_error($ch); 
}

curl_close($ch);

以下是生成的错误:

  • getaddrinfo(3)domain.net:443
  • 失败
  • 无法解析主机'domain.net'
  • 关闭连接#0

所以,它看起来像一个简单的404错误,但重点是请求的URL确实存在,并且可以从浏览器中获得... 我不知道为什么只有cURL才能提供资源。

0 个答案:

没有答案