前端使用axios中post访问.net core3.0后台数据的时候不可以传对象,不可以带请求头?出现400、405、415(已解决)
作者:互联网
后端在startup里边加跨域配置如下:
public void ConfigureServices(IServiceCollection services)
{
//配置跨域处理,允许所有来源
services.AddCors(options =>
{
options.AddPolicy("any", builder =>
{
builder.WithMethods("GET", "POST", "HEAD", "PUT", "DELETE", "OPTIONS") //允许任何来源的主机访问
.AllowAnyOrigin()
.AllowAnyHeader();
//.AllowCredentials();//指定处理cookie
});
});
services.AddControllers();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseAuthorization();
//跨域配置
app.UseCors("any");
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers().RequireCors("any");
});
}
标签:axios,跨域,app,415,void,env,400,services,any 来源: https://www.cnblogs.com/Ai-Dou/p/15042419.html