2010-06-07 84 views
5
org.apache.http.client.methods.HttpGet; 

HttpGet method = new HttpGet(url.toExternalForm()); 
method.getParams() 

Whare are these params?他們是查詢字符串?似乎沒有簡單的方法可以使用org.apache.http.client.methods.http Get對於HttpGet方法什麼是getParams()?

回答

14

按照Http Client tutorial,你可以這樣做:

URI uri = new URIBuilder() 
     .setScheme("http") 
     .setHost("www.google.com") 
     .setPath("/search") 
     .setParameter("q", "httpclient") 
     .setParameter("btnG", "Google Search") 
     .setParameter("aq", "f") 
     .setParameter("oq", "") 
     .build(); 
HttpGet httpget = new HttpGet(uri); 
System.out.println(httpget.getURI()); 
+0

@Mark Byers:鏈接固定並更新代碼 – 2013-10-03 21:39:14

0

http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/HttpMethodBase.html#getParams%28%29

getParams

公共HttpMethodParams getParams()方法

Returns HTTP protocol parameters associated with this method. 

Specified by: 
    getParams in interface HttpMethod 

Returns: 
    HTTP parameters. 
Since: 
    3.0 
See Also: 
    HttpMethodParams 

請求的參數的完整列表可以在http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/params/HttpMethodParams.html

+0

問題是關於httpclient 4.x,你的答案是關於3.x. – user1338062 2013-11-28 16:01:59