RestTemplate中文乱码问题

  使用RestTemplate传输带有图片的表单时,需要对表单中的中文参数进行URL编码,

  eg :URLDecoder.decode(name);               // 使用默认的解码

      params.add("name", URLEncoder.encode(name));  // 使用默认的编码

     URLDecoder.decode(name,"UTF-8");   // 使用指定的解码

     params.add("name", URLEncoder.encode(name,"UTF-8"));  // 使用指定的编码

 

  注意:编码和解码时,要么都指定编码 ,要么都不指定编码,一边指定编码,一边不指定编码,是错误的。 

posted @ 2013-11-22 19:28  coreWars  阅读(872)  评论(0编辑  收藏  举报