Two calls on demand: from http 204 and 200

I have implemented the Cors policy in core with network core: In Startup.cs

the section ConfigureServices

I added the following cors policy

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

      

I got a weird problem after adding a CORS policy, each time a POST is called from the UI, two calls are made: the first calls return with 204, and the other call returns data with a 200 status code.

two calls on request

+3


source to share


1 answer


The first is a pre-check request . The main goal is to determine if it is safe to send a real request. Cross-site requests are prepended because they can have implications for user data.

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

This is a request OPTIONS

using two HTTP request headers: Access-Control-Request-Method and Access-Control-Request-Headers and an Origin header.

A pre-check request is automatically issued by the browser when needed.



This HTTP Access Control (CORS) describes the conditions that, if true, the request is requested.

+7


source







All Articles