Processing
 

text/plain Media Type not being accepted for WebApi v2

07/09/2016 14:40#1

Rob Scott

Member

Joined at: 9 months ago

Post: 5

Thank: 0

Thanked: 0

This problem started off with IE9, where for POST requests, the contentType has to be text/plain, and application/json will not work.

I've added the moonscript and proceeded to use contentType: text/plain. I've also added the custom media type to the api, as shown on numerous forms below:

And added the insertion of the text/plain media type to the WebApiConfig

config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html")); config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; config.Formatters.JsonFormatter.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;  // allows 'text/plain' as a supported media type config.Formatters.Add(new TextMediaTypeFormatter()); 

However, when posting in IE9 (using emulation), I am still receiving a 415 Unsupported Media Type

Key Value Response HTTP/1.1 415 Unsupported Media Type

$.ajax({     type: "POST",     url: hope_forms.viivApiUrl + 'newsletter',     contentType: 'text/plain',     data: JSON.stringify(model),     success: function (data) {            .....     },     error: function (responseText) {            console.log(responseText)            modal.showModal('Something went wrong, please try again.');    }                     }); 

Addition:

Here's the full blown WebApiConfig in the event that something is out of order:

var cors = new EnableCorsAttribute("*", "*", "*"); config.EnableCors(cors);  config.Routes.MapHttpRoute(     name: "DefaultApi",     routeTemplate: "api/{controller}/{id}",     defaults: new { id = RouteParameter.Optional } );  // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type. // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries. // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712. //config.EnableQuerySupport();  config.EnableSystemDiagnosticsTracing();   //config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html")); config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; config.Formatters.JsonFormatter.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;  // allows 'text/plain' as a supported media type config.Formatters.Add(new TextMediaTypeFormatter()); 

I also changed the ajaxTransport xhr wrapper to use this instead: https://github.com/gfdev/javascript-jquery-transport-xdr

Similar articles

IE9 dosen't support my Button Tag

4 months ago - Reply: 0 - Views: 14

SSRS 2016 Web protal in IE8

4 months ago - Reply: 0 - Views: 13

how to handle @keyframes not supported by ie9?

4 months ago - Reply: 0 - Views: 5

Detect Windows XP in Firefox with JS

4 months ago - Reply: 1 - Views: 47

IE8 Not showing divs with floats

4 months ago - Reply: 2 - Views: 130

Including ECMA 5 script in IE8

5 months ago - Reply: 1 - Views: 98

XDomainRequest does not work in ie8 & ie9

5 months ago - Reply: 0 - Views: 10

How to minify angular.js?

5 months ago - Reply: 1 - Views: 30

VBA and IE8 - scrape text buried in table

5 months ago - Reply: 1 - Views: 37

Detect http satus IE10

5 months ago - Reply: 0 - Views: 6

how to compress angular.js?

5 months ago - Reply: 0 - Views: 3

vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re