我正在使用来自 Chris Kacerguis 的 Codeigniter 中的 restserver,并使用会话设置 rest_auth。当我登录时,我访问了 view.php 通过file_get_contents获得响应的页面,它返回 401 Unauthorized。当我在新选项卡中访问 API 的直接页面时,它会正确返回 json。
view.php以这种方式加载 API 内容:
json_decode(file_get_contents('https://example.com/api/proces/'), true);
响应:
遇到 PHP 错误
严重性:警告
消息:file_get_contents(我需要删除链接):打开失败>流:HTTP 请求失败!HTTP/1.1 401 未经授权
发生了什么?