微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.jb51.cc/aspnet/246630.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐