[function.fopen]:打开流失败:HTTP 请求失败! HTTP/1.1 401 未经授权

发布于 2024-09-11 22:58:54 字数 148 浏览 1 评论 0原文

[function.fopen]:打开流失败:HTTP 请求失败! HTTP/1.1 401 Unauthorized

我定期收到此错误,即它仅在随机时间发生,任何想法会导致此错误,我已检查我的 php.ini 并将allow_url_fopen 设置为 true。

[function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized

I am periodically getting this error, i.e it is only happening at random times, any ideas what would cause this, i have checked my php.ini and allow_url_fopen is set to true.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

零時差 2024-09-18 22:58:54

如果站点需要基本身份验证,您可以通过以下方式提供凭据:

fopen("http://user:[email protected]/path/to/resource", "r");

如果它使用摘要身份验证,您必须通过读取失败响应的标头并发送具有正确标头的新响应来手动处理它。请参阅 HTTP 上下文选项 了解如何读取和设置标头并了解如何消化适用于使用 PHP 进行 HTTP 身份验证

您还可以使用 cURL 扩展HTTP PECL 扩展

If the site requires basic authentication, you can give your credentials this way:

fopen("http://user:[email protected]/path/to/resource", "r");

If it uses digest authentication, you'll have to handle it manually by reading the headers of the failed response and sending a new one with the correct headers. See HTTP context options for how to read and set headers and see how digest works in HTTP authentication with PHP.

You can also use the cURL extension or the HTTP PECL extension.

凝望流年 2024-09-18 22:58:54

10.4.2 401 未经授权

该请求需要用户
验证。回应必须
包含 WWW-Authenticate 标头
字段(第 14.47 节)包含
适用于所请求的挑战
资源。客户可以重复
具有适当授权的请求
标头字段(第 14.8 节)。如果
请求已包含授权
凭据,然后是 401 响应
表示已授权
拒绝提供这些凭据。如果
401响应包含相同的内容
挑战作为先前的响应,并且
用户代理已经尝试过
至少进行一次身份验证,然后
应该向用户提供实体
这是在答复中给出的,因为
该实体可能包括相关的
诊断信息。 HTTP访问
身份验证在“HTTP
身份验证:基本身份验证和摘要身份验证
访问认证”[43]。

状态代码定义

10.4.2 401 Unauthorized

The request requires user
authentication. The response MUST
include a WWW-Authenticate header
field (section 14.47) containing a
challenge applicable to the requested
resource. The client MAY repeat the
request with a suitable Authorization
header field (section 14.8). If the
request already included Authorization
credentials, then the 401 response
indicates that authorization has been
refused for those credentials. If the
401 response contains the same
challenge as the prior response, and
the user agent has already attempted
authentication at least once, then the
user SHOULD be presented the entity
that was given in the response, since
that entity might include relevant
diagnostic information. HTTP access
authentication is explained in "HTTP
Authentication: Basic and Digest
Access Authentication" [43].

Status Code Definitions

微暖i 2024-09-18 22:58:54

正如玛吉指出的那样,您正在尝试访问需要身份验证的网站。 fopen() 不支持 HTTP 基本身份验证,因此您必须使用客户端URL库来实现此类功能。

这已经讨论过。

You are trying to access a site that requires authentication, as maggie pointed out. fopen() does not support HTTP Basic Authentication, so you must use the Client URL Library to achieve such functionalities.

This has been discussed before.

眼眸印温柔 2024-09-18 22:58:54

任务 - fopen 具有基本的 http 身份验证。

$auth_header = 'Authorization: Basic '.base64_encode("$user:$password");

$f = fopen($url, $open_mode,false, stream_context_create(
    'http'=>array(
        'header' => array($auth_header,$some_other_header,$some_yet_header),
    ),
));

task - fopen with basic http authentication.

$auth_header = 'Authorization: Basic '.base64_encode("$user:$password");

$f = fopen($url, $open_mode,false, stream_context_create(
    'http'=>array(
        'header' => array($auth_header,$some_other_header,$some_yet_header),
    ),
));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文