【发布时间】:2014-11-19 15:04:27
【问题描述】:
我编写了简单的 php 代码来获取一些 url 内容,但它不起作用 它返回此错误
file_get_contents(http://www.nature.com/nature/journal/v508/n7496/full/nature13001.html) [function.file-get-contents]:打开流失败:HTTP 请求失败! HTTP/1.0 401 未经授权
这是我的代码。请帮帮我.tnx
$content=file_get_contents('http://www.nature.com/nature/journal/v508/n7496/full/nature13001.html');
echo $content;
【问题讨论】:
-
"HTTP/1.0 401 Unauthorized" 你这是什么意思? en.wikipedia.org/wiki/List_of_HTTP_status_codes 而且,file_get_contents 的http wrapper 不会发送正常的http 头,可以在服务器端识别...
-
阅读更新的评论。如果您能够使用浏览器访问此 URL,但 file_get_contents 给您该错误,那么您必须使用 cURL,例如,发送完整的 http 标头集。顺便说一句,您可以从学院/大学网络访问该文章,但如果脚本在校园网络之外的某些服务器上运行,它也会出现此 401 错误。
-
你的意思是这是我的代码:
$content=file_get_contents("http://www.nature.com/nature/journal/v508/n7496/full/nature13001.html"); -
我只需要这个url的内容和浏览器显示的一样。用于模式加工和数据挖掘。
-
对不起,我也尝试使用 cURL 但它不起作用:(
标签: php http-status-code-401 article