I'm using the restserver in Codeigniter from Chris Kacerguis and I setup rest_auth with session. When I'm logged in, I access the page whose view.php get the response through file_get_contents and it's returning 401 Unauthorized. When I access the API's direct page in a new tab, it returns the json correctly.
the view.php is loading the API content in this way:
json_decode(file_get_contents('https://example.com/api/proces/'), true);
the response:
A PHP Error was encountered
Severity: Warning
Message: file_get_contents( I needed to remove the link ): failed to open >stream: HTTP request failed! HTTP/1.1 401 Unauthorized
What's happening?
I see your example url is using "https" and it is possible that your Apache / Nginx server is not configured correctly to handle the SSL in this way, but it would work fine with the certificate in the browser.
I would suggest you use curl as an alternative instead.
from here https://github.com/zg/curl_get_contents
Or of course you could use curl directly.