两次致电请求:http 204和200 [英] Two calls on Post request: with http 204 and 200

查看:576
本文介绍了两次致电请求:http 204和200的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已在点网核心应用程序中实施了Cors策略:
ConfigureServices 下的 Startup.cs 中我添加了以下cors政策

I have implemented Cors policy in dot net core application: In Startup.cs under ConfigureServices I have added the following cors policy

services.AddCors(options =>{
                options.AddPolicy("CorsPolicy",
                    builder => builder.AllowAnyOrigin()
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .AllowCredentials());
            });

在添加CORS策略后,我面临一个奇怪的问题,从UI进行的每个POST调用中都有两个进行的呼叫:第一个呼叫返回204,其他呼叫返回状态代码200。

I'm facing a strange issue after adding CORS policy, on every POST call from UI there are two calls made: first calls returns with 204 and other call returns the data with 200 status code.

推荐答案

第一个是已完成的请求。主要目标是确定实际请求是否可以安全发送。跨站点请求被预检,因为它们可能会影响用户数据。

First one is a preflighted request. The main goal is to determinate whether the actual request is safe to send. Cross-site requests are preflighted since they may have implications to user data.


CORS预检请求是一个CORS请求,用于检查是否

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

这是一个使用两个HTTP请求标头的 OPTIONS 请求:Access-Control-Request -Method和Access-Control-Request-Headers,以及Origin头。

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访问控制(CORS)描述条件,如果为true,则请求被预检。

This HTTP access control (CORS) describe conditions that if true then request is preflighted.

这篇关于两次致电请求:http 204和200的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆