2010-06-07 85 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