php的file_get_contents失败,但ping工程

问题描述:

我想写一个非常简单的PHP脚本来测试主机api.twitter.com是否已启动。但是当我做php的file_get_contents失败,但ping工程

file_get_contents('https://api.twitter.com') 

然后我得到的错误

Warning: file_get_contents(https://api.twitter.com): 
failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found 

简单ping在命令行中工作正常,并file_get_contents正常工作的其他网址,如http://google.com

之前我给curl试试我以为我会看到如果我做错了file_get_contents()

+5

拷贝到您的浏览器的URL https://api.twitter.com:这真的是一个404. – darma 2013-04-07 08:54:01

+0

怎么样才能确定呢? – mulllhausen 2013-04-07 08:56:00

+0

Ping是ICMP,HTTP是TCP。 – Gumbo 2013-04-07 08:56:55

https://api.twitter.com本身确实会返回404 - 正常。如果你想与API交互,你必须使用类似:

​​

文档:https://dev.twitter.com/docs/api/1.1/get/statuses/mentions_timeline

+0

谢谢。我想我会将404作为服务器启动并区分这和服务器无法访问(当api.twitter.com停机时) – mulllhausen 2013-04-07 09:03:16