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'];
[....]
}
可以顯示示例curl請求如何訪問您的api。例如:$ curl --include --user root:root123 --request POST http://example.com/ –