How to send JSON in C# with DataContractJsonSerializer without charset? -


i use datacontractjsonserializer , stringcontent send json web service:

datacontractjsonserializer serializer = new datacontractjsonserializer(typeof(employee)); memorystream ms = new memorystream(); serializer.writeobject(ms, employee); ms.position = 0; streamreader sr = new streamreader(ms); stringcontent jsoncontent = new stringcontent(sr.readtoend(),                                system.text.encoding.utf8, "application/json"); // later httpclient.postasync(uri, jsoncontent) 

this results in content-type header:

content-type: application/json; charset=utf-8 

is possible leave off charset , have following header?

content-type: application/json 

i don't see overload on stringcontent this.

i had been having exact same problem, no matter set charset to, claim trying use "unsupported media type". found using method of leaving charset blank (as slack trying do) solved problem. trick specify content type - absolutely required - later (i did on next line):

stringcontent content = new stringcontent("whatever=something"); content.headers.contenttype = new mediatypewithqualityheadervalue("application/json"); 

(please excuse not-really-json formatting of content, isn't point of example.)


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

node.js - Bad Request - node js ajax post -

uitableview - Create and use custom prototype table cells in xamarin ios using storyboard -