简体   繁体   English

批处理请求必须具有“ Content-Type”标头/“ multipart / mixed”作为媒体类型

[英]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.

相关问题 Flurl获取带有“ Content-Type”标头的请求? - Flurl get request with “Content-Type” header? 内容类型-WebAPI-请求标头 - Content-Type - WebAPI - Request Header 请求包含实体主体但没有 Content-Type 标头。推断的媒体类型 application/octet-stream 不支持此资源 - The request contain entity body but no Content-Type header.The inferred media type application/octet-stream is not support for this resource IsMimeMultipartContent无法处理Multipart Content-Type标头的Type参数中的其他斜杠 - IsMimeMultipartContent cannot handle Additional Slash in Type parameter of Multipart Content-Type header 如何将Content-Type标头添加到.Net GET Web请求? - How to add the Content-Type header to a .Net GET web request? 如何为 HttpClient 请求设置 Content-Type header? - How do you set the Content-Type header for an HttpClient request? 错误 415 请求包含实体主体但没有 Content-Type header - Error 415 The request contains an entity body but no Content-Type header POST请求标头中的content-type缺少FormData边界 - FormData boundary missing from content-type in POST request header 将内容类型标头添加到 httpclient GET 请求 - Add content-type header to httpclient GET request 验证请求内容类型 - Validating Request Content-Type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM