2017-09-02 88 views
1

我想在我的REST API(PHP - Slim Framework)中实现HTTP-Basic-Authentication。 如果我发送POST请求到受保护的URL,它会显示一个窗口'Authentication required',我可以在其中填写我的凭据,但我总是得到一个错误 401未授权PHP - REST - Slim Framework HTTP Basic Auth - 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']; 
[....] 
} 
+0

可以显示示例curl请求如何访问您的api。例如:$ curl --include --user root:root123 --request POST http://example.com/ –

回答