我想實現http DELETE。該應用程序是用PHP和slim3框架編寫的。前端是角形2.超薄3 Http刪除方法不起作用
如果模式看起來像:$slimApp->delete('/delete', ...)
一切都很好。
只要我喜歡介紹PARAMS:$slimApp->delete('/delete/{id}', ...)
我得到以下錯誤:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
我已經閱讀文檔https://www.slimframework.com/docs/cookbook/enable-cors.html但卻我無法得到它的工作。
這裏是我的中間件:
<?php
class MyMiddleware {
public function __invoke(Request $req, Response $res, $next) {
$res->withHeader('Access-Control-Allow-Origin', 'http://localhost:8100')
->withHeader('Access-Control-Allow-Credentials', 'true')
->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization')
->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
return $next($req, $res);
}
}
$app = new \Slim\App([
"settings" => [
"determineRouteBeforeAppMiddleware" => true
]
]);
$app->add(new MyMiddleware());
任何想法可能是什麼問題呢?
您能爲此路線顯示回撥嗎? –