php - RestServer in Codeigniter: 401 Unauthorized response when loading in view -


i'm using restserver in codeigniter chris kacerguis , setup rest_auth session. when i'm logged in, access page view.php response through file_get_contents , it's returning 401 unauthorized. when access api's direct page in new tab, returns json correctly.

the view.php loading api content in way:

json_decode(file_get_contents('https://example.com/api/proces/'), true); 

the response:

a php error encountered

severity: warning

message: file_get_contents( i needed remove link ): failed open >stream: http request failed! http/1.1 401 unauthorized

what's happening?

i see example url using "https" , possible apache / nginx server not configured correctly handle ssl in way, work fine certificate in browser.

i suggest use curl alternative instead.

json_decode(curl_get_contents('https://example.com/api/process/')); 

from here https://github.com/zg/curl_get_contents

or of course use curl directly.

$url = 'https://example.com/api/process/'; $request = curl_init(); curl_setopt($request, curlopt_url, $url); curl_setopt($request, curlopt_returntransfer, true); curl_setopt($request, curlopt_header, false); $data = curl_exec($request); curl_close($request); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -