CodeIgniter Forums
CI throws 401 on a CURL request - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: CI throws 401 on a CURL request (/showthread.php?tid=87391)



CI throws 401 on a CURL request - sjender - 04-14-2023

I have created a simple API to check the newest version of software.
If I call this endpoint directly in the browser everything works.
But when I try to get the same contents via curl, a 401 is thrown....
This is the request:
PHP Code:
$handler curl_init($url);
curl_setopt($handlerCURLOPT_RETURNTRANSFERtrue);
curl_setopt($handlerCURLOPT_SSL_VERIFYPEERfalse);
curl_setopt($handlerCURLOPT_HTTPHEADER$headers);
curl_setopt($handlerCURLOPT_POST1);
curl_setopt($handlerCURLOPT_POSTFIELDS$postFields);
$apiOutput curl_exec($handler); 

And this is the (simplified) endpoint:
PHP Code:
    

public function versionInfo()
    {
        $output = ['version' => 2];
        return $this->response->setJSON($output);

    



RE: CI throws 401 on a CURL request - InsiteFX - 04-14-2023

READ:

debugbar - HTTP 401 Unauthorized Access Error