我正在构建一个.Net Core Api,它将被Angular 7客户端使用,但是由于任何原因,我对每个POST请求都有2个请求
createRole(role: RoleModel): any {
return this.httpClient.post(this.appConfig.apiUrlRole, JSON.stringify(role), { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) });
}
控制器:
[HttpPost]
public async Task<IActionResult> PostAsync([FromBody]RoleRecord roleRecord)
{
await _roleRecordService.InsertAsync(roleRecord);
return Ok();
}
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddCors();
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy",
builder => builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
});
..
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
....
app.UseCorsMiddleware();
app.UseMvc();
//app.UseCors("CorsPolicy");
}
}
谢谢