Return-Path: Delivered-To: apmail-hc-httpclient-users-archive@www.apache.org Received: (qmail 26130 invoked from network); 16 Mar 2010 00:18:33 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 16 Mar 2010 00:18:33 -0000 Received: (qmail 52317 invoked by uid 500); 16 Mar 2010 00:18:33 -0000 Delivered-To: apmail-hc-httpclient-users-archive@hc.apache.org Received: (qmail 52283 invoked by uid 500); 16 Mar 2010 00:18:33 -0000 Mailing-List: contact httpclient-users-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-users@hc.apache.org Received: (qmail 52275 invoked by uid 99); 16 Mar 2010 00:18:33 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Mar 2010 00:18:33 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of charroch@gmail.com designates 209.85.220.223 as permitted sender) Received: from [209.85.220.223] (HELO mail-fx0-f223.google.com) (209.85.220.223) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Mar 2010 00:18:26 +0000 Received: by fxm23 with SMTP id 23so784598fxm.38 for ; Mon, 15 Mar 2010 17:18:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=8K5Tg5XL54SvhPCkkqXb5bTSuGzmxPvLrBBWM10H8U8=; b=T/6bqhgnLRVd3e0haMF8k8Ip333iCDVgSPGtQB2kl+5CPamA7feaBVWfgAZXCkbNZb VpZ/4q9ZCF/+Hd0yZwp+/3vevSCScZjOedcFclcr80lN/g36fLLve+9WKdO490a8k8TL IsDvLdsHhg3HLxXHW8H4+G8yMoFRv5qWW6uqU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=dCffA624Wv/fRuOj7mHOalc1Zu4TokFYcgXSuYJqcr9isu/WjWG3idyilf/v74g5iK DprUs3PjgrEC6vtAk23ggSqYvzmqrYw20KGFaZLqoppC3wenxDGYONiEP5Dd44AaXh8P 5+D0V4tiEogYvGOoMUimpLMdlx9f/ZcReR43M= MIME-Version: 1.0 Received: by 10.223.29.199 with SMTP id r7mr7535191fac.73.1268698685718; Mon, 15 Mar 2010 17:18:05 -0700 (PDT) In-Reply-To: <74ccdfa91003151706j3c8f0d51u1111154cc4979c1f@mail.gmail.com> References: <74ccdfa91003150207m585a9e3egee7d430e53e273e1@mail.gmail.com> <4B9EB02A.70909@apache.org> <74ccdfa91003151706j3c8f0d51u1111154cc4979c1f@mail.gmail.com> Date: Tue, 16 Mar 2010 00:18:05 +0000 Message-ID: <74ccdfa91003151718q41772ac0w18ac27a006d33eeb@mail.gmail.com> Subject: Re: best practice for name/value parameter in httprequest From: Carl-Gustaf Harroch To: HttpClient User Discussion Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Checked: Checked by ClamAV on apache.org To give a more palpable example, lets say I want to add a NameValue pair to a GET request. I have the following: HttpGet get = new HttpGet("http://google.com/search"); ... List l = URLEncodedUtils.parse(get.getURI(), "UTF-8"); l.add(new NameValuePair("q", "test"); URI uri = URIUtils.createURI("http", "google.com", -1, "/search", URLEncodedUtils.format(l, "UTF-8"), null); get.setURI(uri); This is quite similar to POST and I just feel it to be a bit verbose. Any best practices lying around? On 16 March 2010 00:06, Carl-Gustaf Harroch wrote: > Just found it after I posted my query. Still, I believe there is room > for improvements. Maybe a wrapper which would add the ability to > add/delete/get/clear a NameValuePair from the Entity/URI against a > POST/PUT/GET etc... Throughout development, defining and setting > parameters is probably what I do most - creating the URI/Entity during > request creation. Especially in REST calls. For instance adding a > session token - in the entity or URI depending on the request - is > quite common and in terms of concern should not be on the HttpRequest > in my opinion. I am currently implementing a HttpRequestInterceptor > for the forth mentioned problem. > > Thanks for the input, > ./C > > On 15 March 2010 22:09, Oleg Kalnichevski wrote: >> 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 formparams = new ArrayList(); >>> 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 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 >> >> > > > > -- > Carl-Gustaf Harroch > -- Carl-Gustaf Harroch --------------------------------------------------------------------- To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org For additional commands, e-mail: httpclient-users-help@hc.apache.org