【问题标题】:Curl request failing (times out)卷曲请求失败(超时)
【发布时间】:2014-09-22 02:04:53
【问题描述】:

我一直在从 https nasa.gov 站点通过 cron 作业请求 kml 文件。它已经工作了多年,现在才开始失败。我没有收到任何 curl 错误 - 请求只是超时。美国国家航空航天局的网站一定发生了一些变化。

$curl_connection = 
  curl_init("http://firms.modaps.eosdis.nasa.gov/active_fire/kml/USA_contiguous_and_Hawaii_24h.kml");

//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($curl_connection, CURLOPT_USERAGENT, 
  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, true);
curl_setopt( $curl_connection, CURLOPT_SSL_VERIFYHOST, 0);

//perform our request
$string = curl_exec($curl_connection);

//show information regarding the request
print_r(curl_getinfo($curl_connection));
echo curl_errno($curl_connection) . '-' . 
curl_error($curl_connection);

//close the connection
curl_close($curl_connection);

【问题讨论】:

  • 如果你什么都没做,那么也许 nasa 有,问他们\

标签: php curl https kml


【解决方案1】:

NASA 网站一定发生了一些变化。

看起来他们现在正在使用 HTTPS:

$ curl http://firms.modaps.eosdis.nasa.gov/active_fire/kml/USA_contiguous_and_Hawaii_24h.kml
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="https://firms.modaps.eosdis.nasa.gov/active_fire/kml/USA_contiguous_and_Hawaii_24h.kml">here</a>.</p>
</body></html>

这些年来你在没有真实性保证的情况下使用这些数据:)

这可能对您有用:How do I tell curl to follow HTTP redirects?

网址也可能已更改。但这是留给读者的练习。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-29
    • 2011-04-22
    • 2011-09-16
    • 2019-07-07
    • 2022-01-07
    • 2019-08-12
    • 2018-09-20
    • 2019-01-27
    相关资源
    最近更新 更多