How to change default Web API 2 to JSON formatter?

后端 未结 7 1118
面向向阳花
面向向阳花 2020-12-13 14:40

I have a Web API project that returns some product data. It negotiates the return type correctly depending on the Accept header (JSON/XML) of the request. The problem is, if

7条回答
  •  天涯浪人
    2020-12-13 15:03

    Add this in your App_Start/WebApiConfig.cs:

    config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
    

提交回复
热议问题