File-get-contents failed to open stream Unauthorized

北城以北 提交于 2019-11-29 12:23:44

In your url try:

http://user:password@site/ 

(append whatever the rest of the URL for your API should be)

Just put the user info into the URL:

$url = 'http://user:password@domain.tld/foo/bar/whatever';

The 401 Unauthorized status code means that you should have authenticated, but that you haven't, or that you have authenticated with the wrong credentials. It is most commonly used when using HTTP authentication, which is authentication built into the HTTP protocol, and therefore is universal, not only for HTML documents, but for anything transfered over the HTTP protocol.

To authenticate with HTTP authentication, simply add username:password@ before the hostname in the URL. For instance:

http://foobar:mysupersecretpassword@example.com/passwordprotected/

This would request the /passwordprotected/ directory from example.com with the username foobar and the password mysupersecretpassword.

It's not any worse than that. :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!