symfony apache没有发送授权头

时间:2017-06-29 20:22:54

标签: symfony http-headers apache2

我在.htaccess中重写了规则

# Sets the HTTP_AUTHORIZATION header removed by Apache
RewriteCond %{HTTP:Authorization} .
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

尝试测试发送jwt授权

$res = $this->client->request('GET', 
    'http://localhost/api/private', [
        'headers' => [
        'Authorization' => 'Bearer JWTTOKEN'
     ]
]);

http://localhost/api/private resulted in a 401 Unauthorized response:\n{\"code\":401,\"message\":\"JWT Token not found

enter image description here

2 个答案:

答案 0 :(得分:0)

您发送的是GET,可能应该发送POST

$res =   $this->client->request('POST', 
'http://localhost/api/private', [
  'headers' => [
      'Authorization' => 'Bearer JWTTOKEN'
  ]
]);

答案 1 :(得分:0)

清除我的prod缓存并在此处仔细检查我的虚拟主机文件设置https://symfony.com/doc/current/setup/file_permissions.html我开始得到一个空的响应,问题是我得到一个空的回复我没有使用guzzle正确我有从响应正文得到我的回复并解码它

return new JsonResponse(json_decode($res->getBody()->getContents()));