你的位置:首页 > Java教程

[Java教程]httpclient 4.2.1 文件上传中文、文件名中文乱码

HttpPost方式
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null, Charset.forName("UTF-8"));
FileBody bin = new FileBody(new File(localFile));
StringBody userName = new StringBody("张三", ContentType.create("text/plain", Consts.UTF_8));
reqEntity.addPart("file", bin);
reqEntity.addPart("userName ", userName );
httpPost.setEntity(reqEntity);
PostMethod方式

PostMethod postMethod = new PostMethod(url);
postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8");