文件获取内容无法打开流未经授权 [英] File-get-contents failed to open stream Unauthorized
问题描述
我正在尝试使用file_get_contents.I确保在php.ini中启用了allow_url_fopen。截至目前,它告诉我:
I am trying to use file_get_contents.I have made sure that allow_url_fopen is enabled in php.ini. As of now it is telling me:
[function.file-get-contents]:无法打开流:HTTP请求失败! HTTP / 1.1 401未经授权
[function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized
我所做的就是以下内容,我可以通过浏览器轻松访问。
All I'm doing is the following, which I can access through browser without a problem.
$url=('http://site/@api/users/=john_smith@site.com/properties');
$xmlString=file_get_contents($url);
我认为这是一个身份验证问题但不确定如何从脚本中提供正确的凭据本身。任何想法将不胜感激。
I believe this is an authentication issue but not sure how I can supply the proper credentials from within the script itself. Any ideas would be greatly appreciated.
推荐答案
在您的网址中尝试:
http://user:password@site/
(追加其余的您的API的网址应为)
(append whatever the rest of the URL for your API should be)
这篇关于文件获取内容无法打开流未经授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!