symfony apache 不发送授权 header

symfony apache not sending authorization header

我在 .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

您正在发送 GET 并且应该发送 POST

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

清除我的 prod 缓存并仔细检查我的虚拟主机文件设置后 https://symfony.com/doc/current/setup/file_permissions.html我开始收到空响应,问题是我收到空响应 我没有正确使用 guzzle我必须从响应体中得到我的响应并对其进行解码

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