c# - text/plain Media Type not being accepted for WebApi v2 -


this problem started off ie9, post requests, contenttype has text/plain, , application/json not work.

i've added moonscript , proceeded use contenttype: text/plain. i've added custom media type api, shown on numerous forms below:

and added insertion of text/plain media type 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' supported media type config.formatters.add(new textmediatypeformatter()); 

however, when posting in ie9 (using emulation), still receiving 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 full blown webapiconfig in event 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 following line of code enable query support actions iqueryable or iqueryable<t> return type. // avoid processing unexpected or malicious queries, use validation settings on queryableattribute validate incoming queries. // 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' supported media type config.formatters.add(new textmediatypeformatter()); 

i changed ajaxtransport xhr wrapper use instead: https://github.com/gfdev/javascript-jquery-transport-xdr


note:

as of today, 09/21, i've switched post requests get, still work-around these types post.

i think you've run strange xdomainrequest issue cropped in 2014 according this msdn blog

note: of 2014, xdomainrequest doesn’t appear send content-type header @ all. it’s not clear me when changed.

here's previous question on topic references blog.

this backed documentation jquery extension using. in readme.md

xdomainrequest have limitations:

  • there no content-type header in request

so if check httpcontext.request.contenttype i'm betting it's going null / empty in case should able assign response type of "text/plain" , pray gods works.

basically ie < 10 support xdomainrequest (and xdomainrequest itself) garbage. has been ditched understanding , ie 10 implemented cors support xhr requests


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -