This is my first time asking a question here.
I have a problem with my Web API server in C#.
I explain, I have an application in Angular, under Electron (not developed by me) which makes API calls.
When I start my API server, all requests return 400 error (Bad request). APIs call don't reach the code, nor the Middleware that I tried to develop. I also set the CORS to allow access to all origins or all methods. APIs run fine in a browser or with Postman.
Here it's my API server configuration. I tried a lot of different things and I don't think that's the problem.
services.AddCors(options => {
options.AddDefaultPolicy(policy => {
policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
}
}
//...
//further in code
//...
app.UseRouting();
app.UseCors();
app.UseMiddleware(typeof(CorsMiddleware));
After several tries, I found that queries run correctly when in Chrome dev tools when I disable manual user-agent selection. In Chrome Dev', when you go to Settings -> More tools -> Network conditions. The "Select automatically" condition of the User-Agent is activated and all request return 400 (Bad Request), when I desactivate it, all requests return 200 OK.
automatic user agent selection
This is the only way for queries to run correctly. Is there a solution knowing that I don't have a hand on the Angular code. Is this blocked by Electron? Do I need to add something in the configuration of my API server ? Maybe to open to all User-Agent ?
Thanks