javahttpokhttp

okhttp does not allow for setting of content-type


I have attempted to set the content type header of my request however okhttp automatically adds content-type to the end of the header list and sets it as application/json; charset=UTF-8 although I have simply set it to application/json.

Has anybody else experienced this? If so, I can make a pull request.

I have found out okhttp does not send this header properly via fiddler.


Solution

  • When you create your request body, convert the JSON string to bytes first using whichever character encoding you prefer. If you use a byte[] to create a request body OkHttp won't add a charset parameter to the content type.