For a HttpGet method what are getParams()?

穿精又带淫゛_ 提交于 2019-12-22 06:49:03

问题


org.apache.http.client.methods.HttpGet;

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

Whare are these params? Are they the query string? there seems to be no easy way to add a query string with org.apache.http.client.methods.HttpGet


回答1:


According to the Http Client tutorial, you can do this:

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());



回答2:


These parameters are the HTTP GET request parameters.

For instance in the URL http://www.mysite.com/login?username=mcjones, the parameter username has value mcjones.




回答3:


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

getParams

public 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

The full list of parameters for the request can be found at http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/params/HttpMethodParams.html



来源:https://stackoverflow.com/questions/2989429/for-a-httpget-method-what-are-getparams

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!