UTF-8编码,FileBody在MultipartEntity [英] UTF-8 encoding with FileBody in MultipartEntity
本文介绍了UTF-8编码,FileBody在MultipartEntity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想设置UTF-8编码,同时发送的文件中FileBody我在一个StringBuilder做到这一点。我这样做,是这样的:
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")));
和它工作正常,如果我从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);
服务器UTF-8获取文件名不是。我该如何解决?
server get files names not in UTF-8. How can I fix it?
推荐答案
我根本解决这个问题,方法是:
I solve this issue simply, by:
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE,null,Charset.forName("UTF-8"));
这篇关于UTF-8编码,FileBody在MultipartEntity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文