【发布时间】:2018-01-06 15:36:10
【问题描述】:
我不断收到此错误
警告:file_get_contents 未能打开流:HTTP 请求 失败的! HTTP/1.1 401 未经授权
代码
$url = BASE_URL . 'api/v1/users';
$options = array('http' => array(
'method' => 'GET',
'header' => 'Authorization: Bearer '.$token
));
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
我与我的 api 一起使用的中间件通过 url 参数或标头接受授权;
如果我在参数中使用令牌,它可以工作但无法通过服务器上的标头发送它,导致在本地主机上它工作,
请求是通过不记名令牌授权的,我没有任何用户名和密码来授权请求,如下所示,我只在我的 url 参数中使用令牌。
知道为什么吗?如果不更改所有对 curl 的请求,我该怎么办
$result = file_get_contents(BASE_URL . 'api/v1/users?authorization='.$token, false);
$response = json_decode($result, true);
【问题讨论】:
-
@AnkitSingh 不相关
标签: php slim middleware