asp.net-core – 对Post请求的两次调用:使用http 204和200

前端之家收集整理的这篇文章主要介绍了asp.net-core – 对Post请求的两次调用:使用http 204和200前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在dot net core应用程序中实现了Cors策略:
在ConfigureServices下的Startup.cs中,我添加了以下cors策略
services.AddCors(options =>{
                options.AddPolicy("CorsPolicy",builder => builder.AllowAnyOrigin()
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .AllowCredentials());
            });

添加CORS策略后,我遇到一个奇怪的问题,在每次POST调用时,都会进行两次调用:第一次调用返回204,其他调用返回200状态代码的数据.

解决方法

第一个是 preflighted request.主要目标是确定实际请求是否可以安全发送.跨站点请求具有前瞻性,因为它们可能会对用户数据产生影响.

A CORS preflight request is a CORS request that checks to see if the CORS protocol is understood.

It is an OPTIONS request using two HTTP request headers: Access-Control-Request-Method and Access-Control-Request-Headers,and the Origin header.

A preflight request is automatically issued by a browser when needed.

HTTP access control (CORS)描述了条件,如果为真,则请求被预检.

原文链接:https://www.f2er.com/aspnet/246630.html

猜你在找的asp.Net相关文章