1

我尝试使用愚蠢的代码发送带有 unicode 字符的多部分请求:

                    HttpClient httpClient = new DefaultHttpClient();
                    HttpPost postRequest = new HttpPost(ServerUrl);
                    MultipartEntity reqEntity = new MultipartEntity(
                            HttpMultipartMode.BROWSER_COMPATIBLE,null,Charset.forName(HTTP.UTF_8));
                    reqEntity.addPart("uploaded", new FileBody(image));

                    Charset chars = Charset.forName(HTTP.UTF_8); // Setting up the encoding

                    reqEntity.addPart("paramName",new StringBody(new String(UNICODESTRING.getBytes("UTF-8"),"UTF-8"),chars));

服务器端 servlet 代码是:

List<FileItem> formItems = upload.parseRequest(request);

            if (formItems != null && formItems.size() > 0) {
                // iterates over form's fields

                for (FileItem item : formItems) {
                     if (item.isFormField()) {
                        String fieldname = item.getFieldName();
                        String fieldvalue = item.getString();
                      if(fieldname.equals("paramName")){
                            System.out.println(">>>>>>>>>>>>> the branch name: "+new String(item.getString().getBytes("UTF-8"),"UTF-8"));
                            // then Save to DATABASE
                        }

println 行给出扭曲的字符,例如:تÙتتسÙتتسÙتس 它也按原样保存在数据库中!

谁能帮我解决这个问题...

提前致谢 ,

4

0 回答 0