HttpClient上傳文件時中文問題解決方法

/**
  *
  * @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");
post

//設置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"));url

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

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


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

相關文章
相關標籤/搜索