HttpClient post的用法

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
 public class HttpClientPost{
  public static void main(String []args) throws Exception{
      HttpClient client=new HttpClient();
      String url="http://msc.oceanschedules.com/schedules/schedule-search.do";
     PostMethod postMethod=new PostMethod(url);
      //增加变量
        postMethod.addParameter("lad","09/24/2011");                                
        postMethod.addParameter("dad","11/28/2011");                                
        //postMethod.addParameter("destinationId","124196"); 
       
        postMethod.addParameter("originId","124196");                               
        postMethod.addParameter("origin","Ningbo, Zhejiang, China (CNNGB)" );  
        //postMethod.addParameter("origin","Shanghai, Shanghai, China  (CNSHA)" );
        postMethod.addParameter("destinationId","123991");
        postMethod.addParameter("destination", "Shanghai, Shanghai, China (CNSHA)"); 
        postMethod.addParameter("searchSort", "2"); 
       
        client.executeMethod(postMethod);
        String str="";
        str=new String(postMethod.getResponseBodyAsString().getBytes("utf-8"));
        System.out.println(str);
        postMethod.releaseConnection();
     
   }

}

你可能感兴趣的:(httpclient)