httpclient上传文件,同时带字符串参数 中文乱码问题
2016-03-08 15:18
1211 查看
PostMethod filePost = new PostMethod(URL);
HttpClient client = new HttpClient(connectionManager);
// 通过以下方法可以模拟页面参数提交
try {
Part[] parts = {
new FilePart("upfile", file),new StringPart("idcard", pramMap.get("idcard"))
,new StringPart("name", pramMap.get("name"),"utf-8")};
filePost.setRequestEntity(new MultipartRequestEntity(parts,filePost.getParams()));
client.getHttpConnectionManager().getParams().setConnectionTimeout(60000);
int status = client.executeMethod(filePost);
如飚红代码所示 可以设置StringPart 编码,这样name中文就不会乱码。
HttpClient client = new HttpClient(connectionManager);
// 通过以下方法可以模拟页面参数提交
try {
Part[] parts = {
new FilePart("upfile", file),new StringPart("idcard", pramMap.get("idcard"))
,new StringPart("name", pramMap.get("name"),"utf-8")};
filePost.setRequestEntity(new MultipartRequestEntity(parts,filePost.getParams()));
client.getHttpConnectionManager().getParams().setConnectionTimeout(60000);
int status = client.executeMethod(filePost);
如飚红代码所示 可以设置StringPart 编码,这样name中文就不会乱码。
相关文章推荐
- 安卓BroadcastReceiver组件使用系列3:使用广播来判断数据网络和无线网络的连接情况
- ios (ASIHTTPRequest)获取下载文件大小(size)
- AsyncHttpClient使用
- 云数据中心网络虚拟化——大二层技术巡礼之控制平面一虚多
- IOS学习之:网络数据的XML解析
- Android进阶——Volley+Https给你的安卓应用加上SSL证书(转)
- 云数据中心网络虚拟化——大二层技术巡礼之控制平面多虚一
- 监控工具TCPMon的使用方法
- PHP版本--HTTP session cookie原理及应用
- JAVA利用HttpClient进行POST请求(HTTPS)
- java发送http的get、post请求
- Android网络请求框架之Retrofit(二)
- 我的新博客地址http://xxxbw.github.io/
- 云数据中心网络虚拟化——大二层技术巡礼之初识大二层
- TCP三次握手和四次挥手
- Android 6.0 使用 Apache HttpClient
- 1 Javascript:交互式网络
- android 检查网络连接状态实现步骤
- P2P,UDP和TCP穿透NAT
- 教你识別和区分网络及使用者