您的位置:首页 > 理论基础 > 计算机网络

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中文就不会乱码。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: