[英]The batch request must have a “Content-Type” header / “multipart/mixed” as the media type
Got an error after I add the DefaultODataBatchHandler on my WEB API OData v4. 在我的WEB API OData v4中添加DefaultODataBatchHandler之后,出现错误。
DefaultODataBatchHandler defaultODataBatchHandler = new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer);
In browser I've got this error: The batch request must have a "Content-Type" header. 在浏览器中,我收到此错误: 批处理请求必须具有“ Content-Type”标头。 In POSTMan I've got this error: The batch request must have 'multipart/mixed' as the media type.
在POSTMan中,我收到此错误: 批处理请求必须具有“ multipart / mixed”作为媒体类型。
If I didn't put the code above. 如果我没有将代码放在上面。 I've got this error when accessing the $batch
访问$ batch时出现此错误
"Message": "No HTTP resource was found that matches the request URI 'http://localhost:2288/$batch'.",
"MessageDetail": "No route providing a controller name was found to match request URI 'http://localhost:2288/$batch'"
RouteConfig.cs RouteConfig.cs
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
Got it now. 现在明白了。
I just need to add CORS 我只需要添加CORS
var cors = new EnableCorsAttribute(
"*",
"*",
"*",
"*"
);
config.EnableCors(cors);
And put wildcard for the exposed header. 并将通配符用作暴露的标头。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.