Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter中的RestServer:401在视图中加载时未经授权的响应_Php_Codeigniter_Codeigniter Restserver - Fatal编程技术网

Php Codeigniter中的RestServer:401在视图中加载时未经授权的响应

Php Codeigniter中的RestServer:401在视图中加载时未经授权的响应,php,codeigniter,codeigniter-restserver,Php,Codeigniter,Codeigniter Restserver,我正在使用Chris Kacerguis提供的Codeigniter中的restserver,并使用会话设置rest\u auth。 当我登录时,我访问其view.php通过文件\u get\u contents获得响应的页面,该页面返回401个未经授权的消息。 在新选项卡中访问API的direct页面时,它会正确返回json php以以下方式加载API内容: json_decode(file_get_contents('https://example.com/api/proces/'), tr

我正在使用Chris Kacerguis提供的Codeigniter中的restserver,并使用会话设置rest\u auth。 当我登录时,我访问其view.php通过文件\u get\u contents获得响应的页面,该页面返回401个未经授权的消息。 在新选项卡中访问API的direct页面时,它会正确返回json

php以以下方式加载API内容:

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

遇到一个PHP错误

严重性:警告

消息:file\u get\u contents(我需要删除链接):无法打开>流:HTTP请求失败!HTTP/1.1 401未经授权


发生了什么事?

我看到您的示例url使用了“https”,并且您的Apache/Nginx服务器可能没有正确配置,无法以这种方式处理SSL,但它可以与浏览器中的证书一起正常工作

我建议你用卷曲来代替

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

当然,你也可以直接使用curl

$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);

api需要任何类型的身份验证吗?我尝试过你的建议,但没有成功。我尝试了在网上找到的其他人,但都没有成功。因此,我将设置身份验证一段时间,如果我最终找到解决方案,我将在这里发布它。