How to suppress Charset being automatically added to Content-Type in okhttp

末鹿安然 提交于 2019-11-30 17:38:31

I found the solution:

The following line is the culprit:

RequestBody body = RequestBody.create(mediaType, media);

create has 3 signatures for media:

  • String
  • byte[]
  • File

When I pass a String, it disregards the supplied mediaType and adds the charset to it. Even for image/jpeg it would send

image/jpeg; charset=utf-8

to the server.

Using byte[] or File suppresses that behavior.

I hope this helps you!

[Stupid me - for simplicity I gave it a String during testing, as I didn't care about the body ;-( ]

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!