3 回答

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超7個(gè)贊
App_Start / WebApiConfig.cs
config.Formatters.JsonFormatter.SupportedMediaTypes .Add(new MediaTypeHeaderValue("text/html") );
xml
text/xml
.
Content-Type
application/json
NameSpace
System.Net.Http.Headers
;

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超4個(gè)贊
WebApiConfig
text/xml
Accept
public static class WebApiConfig{ public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml"); config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType); }}

TA貢獻(xiàn)1735條經(jīng)驗(yàn) 獲得超5個(gè)贊
public class BrowserJsonFormatter : JsonMediaTypeFormatter{ public BrowserJsonFormatter() { this.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html")); this.SerializerSettings.Formatting = Formatting.Indented; } public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType) { base.SetDefaultContentHeaders(type, headers, mediaType); headers.ContentType = new MediaTypeHeaderValue("application/json"); }}
config.Formatters.Add(new BrowserJsonFormatter());
- 3 回答
- 0 關(guān)注
- 1463 瀏覽
添加回答
舉報(bào)