HttpClient上传文件时中文问题解决方法

2010/03/24 14:17
阅读数 521

/**
  *
  * @date 2006-10-28
  * @author eric.chen
  * @throws Exception
  */
 private static void go1() throws Exception {
  HttpClient client = new HttpClient();
    PostMethod p = new PostMethod(
    "url/upload/mrsAction.do");

//设置param
  Part[] params = new Part[4];
  StringPart pt = new StringPart("title", "你好摩网wap.moabc.com");
//中文要用这个
  pt.setCharSet("utf-8");
  params[0] = pt;
  StringPart p1 = new StringPart("tags", "歌手");
  p1.setCharSet("utf-8");
  params[1] = p1;
  params[2] = new StringPart("categoryId", "1");
  params[3] = new FilePart("file1", new File("f:/mp3/261728.mp3"));

  MultipartRequestEntity post = new MultipartRequestEntity(params, p
    .getParams());

  p.setRequestEntity(post);
  System.out.println(client.executeMethod(p));


  p.releaseConnection();
  System.out.println("ok");
 }

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部