Ich habe cors für /api/test
einrichten thusly:CORS Preflight Antwort falsch/leer Header
Allow-Origin: http://localhost:8133
Allow-Headers: X-MyHeader
Allow-Method: Get
dh
services.AddCors(options =>
{
options.AddPolicy("default", policy =>
{
policy.WithOrigins("http://localhost:8133")
.WithHeaders("X-MyHeader")
.WithMethods("GET");
});
});
und
app.UseCors("default");
Wenn ich eine GET-Anfrage an /api/test
senden mit dem Header X-MyHeader
mit Axios sendet es eine OPTIONS
Anfrage z.B.
Access-Control-Request-Headers: x-myheader
Access-Control-Request-Method: GET
Host: localhost:8132
Origin: http://localhost:8133
erhalte ich
Access-Control-Allow-Headers: x-myheader
Access-Control-Allow-Origin: http://localhost:8133
Date: {whatever}
server: {whatever}
zurück Warum ist die Access-Control-Allow-Method
Header fehlt?
Nun, wenn ich fügen Sie eine weitere Header wie, X-NotSupportedHeader
z.B.
Access-Control-Request-Headers: x-notsupportedheader
Access-Control-Request-Method: GET
Host: localhost:8132
Origin: http://localhost:8133
Meine Antwort ist
Date: {whatever}
server: {whatever}
Und in der Konsole wir
bekommenXMLHttpRequest cannot load http://localhost:8132/api/test. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8133' is therefore not allowed access.
Warum sind keine Access-Control-Allow-*
Header überhaupt gesetzt, wenn eines der Kriterien nicht?