httpclient上传文件,同时带字符串参数 中文乱码问题

来源:互联网 发布:手机视频合并软件 编辑:程序博客网 时间:2024/05/19 04:07

 

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中文就不会乱码。

0 0
原创粉丝点击