我想在我的REST API(PHP - Slim Framework)中实现HTTP-Basic-Authentication。 如果我向受保护的URL发送POST请求,它会显示一个“需要身份验证”窗口,我可以在其中填写我的凭据,但我总是收到错误 401未经授权。
$app->add(new \Slim\Middleware\HttpBasicAuthentication([
"path" => "/api/v1/video/add",
"realm" => "Protected",
"secure" => false,
"users" => [
"root" => "root123",
"user" => "user"
]
]));
路线:
$app->post('/api/v1/video/add', function (Request $request, Response $response) {
// get POST-Variables
$allPostVars = $request->getParsedBody();
$id = $allPostVars['id'];
[....]
}