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

后端 未结 4 1901
孤街浪徒
孤街浪徒 2021-01-21 17:51

[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, a

4条回答
  •  再見小時候
    2021-01-21 18:20

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

    fopen("http://user:pass@www.example.com/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.

提交回复
热议问题