问题描述
项目中用到httpClient向服务器发送http请求,具体代码如下:HttpClient httpclient = new DefaultHttpClient();HttpPost httppost = new HttpPost("URL");/** * 服务器端request.getHeader("zhongwen");获取 * 的信息为乱码(尝试了一些转码方法), * 麻烦各位大牛帮下忙**/httppost.addHeader("zhongwen", "中文测试");FileBody bin = new FileBody(new File("D://测试附件.zip"));MultipartEntity reqEntity = new MultipartEntity();reqEntity.addPart("upload", bin);httppost.setEntity(reqEntity);HttpResponse response = httpclient.execute(httppost);如果哪位大牛有别的解决方案,可以将“zhongwen”,"upload"两属性传递至服务器,麻烦给下
解决方案
1、客户端method.addRequestHeader("hello", URLEncoder.encode("中文", "UTF-8"));2、服务器value = URLDecoder.decode(value);
解决方案二:
用native2ascii命令把中文测试转换一下:httppost.addHeader("zhongwen", "u4e2du6587u6d4bu8bd5"); native2ascii在java安装目录下
解决方案三:
检查的你的java源代码文件是什么编码,一般用“UTF-8”