簡體   English   中英

批處理請求必須具有“ Content-Type”標頭/“ multipart / mixed”作為媒體類型

[英]The batch request must have a “Content-Type” header / “multipart/mixed” as the media type

在我的WEB API OData v4中添加DefaultODataBatchHandler之后,出現錯誤。

DefaultODataBatchHandler defaultODataBatchHandler = new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer); 

在瀏覽器中,我收到此錯誤: 批處理請求必須具有“ Content-Type”標頭。 在POSTMan中,我收到此錯誤: 批處理請求必須具有“ multipart / mixed”作為媒體類型。

如果我沒有將代碼放在上面。 訪問$ 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

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 }
        );
    }
}

現在明白了。

我只需要添加CORS

        var cors = new EnableCorsAttribute(
            "*",
            "*",
            "*",
            "*"
        );

        config.EnableCors(cors);

並將通配符用作暴露的標頭。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM