Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File-get-contents failed to open stream Unauthorized

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]: 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/[email protected]/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.

like image 385
Aaron Avatar asked Oct 24 '25 03:10

Aaron


2 Answers

In your url try:

http://user:password@site/ 

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

like image 105
Cfreak Avatar answered Oct 25 '25 19:10

Cfreak


Just put the user info into the URL:

$url = 'http://user:[email protected]/foo/bar/whatever';
like image 22
Raoul Duke Avatar answered Oct 25 '25 17:10

Raoul Duke