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)描述了条件,如果为真,则请求被预检.

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....