hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: best practice for name/value parameter in httprequest
Date Mon, 15 Mar 2010 22:09:46 GMT
Carl-Gustaf Harroch wrote:
> Hello
> 
> I have been playing with HttpClient for a while now and I get to know
> the lib. I hope I can hit on some of this mailing list knowledge to
> find a best practise/pattern regarding sending parameters via a
> request.
> 
> In 90% of my projects, I will use HttpGet or HttpPost. The 2 have
> different ways of implementing parameters (not http params but actual
> form/request parameters). For HttpGet, I would use the URIUtils to
> generate a URI while with HttpPost, I would use a list of name value
> pairs which is set in the entity afterwards.
> 
> Now, I am building a very generic request signer which will sign all
> HttpRequest ala OAuth. I use a HttpRequestIntereceptor but need to
> check the instance of the request before adding the signature. Isn't
> there a better way to get all parameters of a request? Should this not
> be made generic? Is there any utilty class I could use.
> 
> For instance if I have the following 2 requests:
> HttpGet get = new HttpGet("http://somestuff.com/?p=v&p2=v2");
> 
> HttpPost post = new HttpPost("http://somestuff.com");
> List<NameValuePair> formparams = new ArrayList<NameValuePair>();
> formparams.add(new BasicNameValuePair(LOGIN, username));
> formparams.add(new BasicNameValuePair(PASSWORD, password));
> post.setEntity(new UrlEncodedFormEntity(formparams, "UTF-8"));
> 
> now, I would like a method of the form:
> 
> List<NameValuePair> getNameValueParams(HttpRequest request);
> or have the method against HttpRequest.
> 
> The above is quite easily implementable but found it so basic and
> general that there must be somebody else hitting similar wonders. Any
> recommendations?
> 

Have you looked at URLEncodedUtils?

http://hc.apache.org/httpcomponents-client/httpclient/apidocs/org/apache/http/client/utils/URLEncodedUtils.html

Oleg

> Cheers,
> ./C
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message