Please Help with network.request() Unsupported Media Type

Can someone explain how to fix this problem, clearly it should not be happening. Corona should not assume I want to add charset to my Content-Type

If I set a header this way:

 local headers = {} headers["Content-Type"] = "application/json" local body = '{"login":"test", "password":"test"}' local params = {} params.body = body params.headers = headers network.request( URL, "POST", loginCallback, params )

If I watch the packet with wireshark Corona is appending  charset=UTF-8 to the end so it is actually sending

Content-Type: application/json; charset=UTF-8

but the server which I have no control over rejects the request as 

Expert Info (Chat/Sequence): HTTP/1.1 415 Unsupported Media Type

How can I stop Corona from appending this, otherwise I cannot write a very important app as like I said I don’t have control of the server.

Also if I use curl or any REST client where I set the header it works flawlessly. but Corona will not let me send exactly the header I set?

Seems like your server doesn’t implement the HTTP standard for Content-Type headers (or it can’t accept UTF-8 encoded text which, while possible, seems pretty unlikely).

Since Corona SDK only tries to fix the charset specification for requests of type “text” you can try specifying that your request is binary and also specify the content type:

local params = { bodyType = "binary", headers = { ["Content-Type"] = "application/json" } }

Supply this to the network.request() call and you should get the kind of request you need.  As always, when swimming against the standards flow, your mileage may vary unexpectedly if some link in the chain tries to “fix” your request (a proxy server for example).

thanks you, this did fix my problem in the interim.

I was able to fix the code that the server was running to add a match rather than a hard type, I submitted a pull request and it has been merged so all is good, thank you

Seems like your server doesn’t implement the HTTP standard for Content-Type headers (or it can’t accept UTF-8 encoded text which, while possible, seems pretty unlikely).

Since Corona SDK only tries to fix the charset specification for requests of type “text” you can try specifying that your request is binary and also specify the content type:

local params = { bodyType = "binary", headers = { ["Content-Type"] = "application/json" } }

Supply this to the network.request() call and you should get the kind of request you need.  As always, when swimming against the standards flow, your mileage may vary unexpectedly if some link in the chain tries to “fix” your request (a proxy server for example).

thanks you, this did fix my problem in the interim.

I was able to fix the code that the server was running to add a match rather than a hard type, I submitted a pull request and it has been merged so all is good, thank you