【发布时间】:2014-01-30 07:03:43
【问题描述】:
我想从这里获取提要http://laimoon.com/feed/jobs?search=female,arts&locations=2 如果我直接在浏览器中浏览此页面,它会显示提要,如果我在 Windows 上的本地主机中使用此代码
$xml=simplexml_load_file("http://laimoon.com/feed/jobs?search=female,arts&locations=2");
print_r($file_contents);
OR
$file_contents = file_get_contents('http://laimoon.com/feed/jobs?search=female,arts&locations=2')
print_r($xml);
Both works fine
但是如果我在我的 linux live 服务器中使用这个代码,那么它会显示这个错误 file_get_contents()
Warning: file_get_contents(http://laimoon.com/feed/jobs?search=female,arts&locations=2): failed to open stream :HTTP request failed! HTTP/1.1 500 Internal Server Error
simplexml_load_file()
的这个错误Warning: simplexml_load_file(http://laimoon.com/feed/jobs?search=female,arts&locations=2): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error
提前致谢:)
【问题讨论】:
-
500 Server error 是服务器端的问题。你可能对此无能为力。但是,
file_get_contents()URL 包装器并不像它可能的那样健壮。使用 curl() 可能对您有用。 -
但是如果这个错误来自服务器端,那么为什么当我直接从浏览器请求该 URL 时它不会发生?
-
正如我所说 - 包装器不是那么好。有时服务器会因为不喜欢请求而返回 500 错误。我也遇到过类似的麻烦。我发现 curl() 通常更可靠。这只是一个建议。
-
好的,我正在尝试通过 Curl 使用它
-
即使我使用 CURL 也会再次出现 500 错误
标签: linux file-get-contents internal-server-error