UTF-8 encoding with FileBody in MultipartEntity

…衆ロ難τιáo~ 提交于 2019-12-23 11:56:08

问题


I want to set UTF-8 encoding while files sending in FileBody as I do it in a StringBuilder. I do it like this:

restClient.AddEntity("body", new StringBody(body, Charset.forName("UTF-8")));

and it works properly if I send different from UTF-8 messages encoding. But if I do like this:

ContentBody fbody = new FileBody(( File )file, "application/octet-stream","UTF-8");
        restClient.AddEntity("files[]", fbody);

server get files names not in UTF-8. How can I fix it?


回答1:


I solve this issue simply, by:

MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE,null,Charset.forName("UTF-8"));



回答2:


I solve this issue, by this params:

entity.addPart("video_title", new StringBody(edtvideo_title.getText().toString(),Charset.forName(HTTP.UTF_8)));


来源:https://stackoverflow.com/questions/13126327/utf-8-encoding-with-filebody-in-multipartentity

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