httpclient 4.2.1 文件上传中文、文件名中文乱码


A 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");


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM