You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Ross Rankin <ro...@bellsouth.net> on 2003/03/17 23:20:07 UTC
SetValue
I'm having a problem with posting. It's HTTPClient is substituting the
"%2B" for pluses. I'm doing the following:
postmethod = new PostMethod(url);
postmethod.setFollowRedirects(true);
postmethod.setPath("/login.cfm");
NameValuePair[] pparms;
pparms = new NameValuePair[4];
for (int i=0; i < pparms.length; i++) {
pparms[i] = new NameValuePair();
}
pparms[0].setName("searchstring_required");
pparms[0].setValue("You+must+enter+a+keyword+to+search+for.");
pparms[1].setName("source");
pparms[1].setValue("keywords");
pparms[2].setName("searchstring");
pparms[2].setValue(keywords);
pparms[3].setName("action");
pparms[3].setValue("search");
try {
postmethod.setRequestBody(pparms);
client.executeMethod(hc,postmethod);
}
catch . Blah blah.
Now if I getValue for say keywords or searchstring_required, they store:
word1+word2+word3. However, when I look at the trace through a proxy, I get
this:
POST /search/search.cfm HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword,
*/*
Referer: http://www.emplawyernet.com/lawyer/job_search.cfm
Accept-Language: en-us
Content-Type: application/x-www-form-urlencoded
Pragma: no-cache
User-Agent: Jakarta Commons-HttpClient/2.0alpha3
Host: www.host.com
Cookie: $Version=0; WEBTRENDS_ID=65.81.133.128-1177704800.29551825; $Path=/
Cookie: $Version=0; CFID=5434634; $Path=/
Cookie: $Version=0; CFTOKEN=90204730; $Path=/
Content-Length: 141
Expect: 100-continue
Connection: keep-alive
Accept-encoding: gzip, deflate
Browser reload detected...
Posting 141 bytes...
searchstring_required=You%2Bmust%2Benter%2Ba%2Bkeyword%2Bto%2Bsearch%2Bfor.
source=keywords
searchstring=word1%2Bword2%2Bword3
action=search
How can I get it to keep the pluses and not substitute the "%2B"?
Thanks,
Ross
Re: SetValue
Posted by Oleg Kalnichevski <o....@dplanet.ch>.
Ross
Just do it like that:
pparms[0].setName("searchstring_required");
pparms[0].setValue("You must enter a keyword to search for.");
and let PostMethod#setRequestBody(NameValuePair[]) do URL-encoding for
you.
I hope this helps
Cheers
Oleg
PS: BTW, PostMethod can't (well, in fact, is not allowed to) do
automatic redirects due to security reasons. Calling
PostMethod#setFollowRedirects(boolean) actually has no effect of what so
ever
On Mon, 2003-03-17 at 23:20, Ross Rankin wrote:
> I'm having a problem with posting. It's HTTPClient is substituting the
> "%2B" for pluses. I'm doing the following:
> postmethod = new PostMethod(url);
> postmethod.setFollowRedirects(true);
>
> postmethod.setPath("/login.cfm");
>
> NameValuePair[] pparms;
> pparms = new NameValuePair[4];
>
> for (int i=0; i < pparms.length; i++) {
> pparms[i] = new NameValuePair();
> }
>
> pparms[0].setName("searchstring_required");
> pparms[0].setValue("You+must+enter+a+keyword+to+search+for.");
> pparms[1].setName("source");
> pparms[1].setValue("keywords");
> pparms[2].setName("searchstring");
> pparms[2].setValue(keywords);
> pparms[3].setName("action");
> pparms[3].setValue("search");
>
> try {
> postmethod.setRequestBody(pparms);
> client.executeMethod(hc,postmethod);
> }
>
> catch . Blah blah.
>
>
> Now if I getValue for say keywords or searchstring_required, they store:
> word1+word2+word3. However, when I look at the trace through a proxy, I get
> this:
>
> POST /search/search.cfm HTTP/1.1
> Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
> application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword,
> */*
> Referer: http://www.emplawyernet.com/lawyer/job_search.cfm
> Accept-Language: en-us
> Content-Type: application/x-www-form-urlencoded
> Pragma: no-cache
> User-Agent: Jakarta Commons-HttpClient/2.0alpha3
> Host: www.host.com
> Cookie: $Version=0; WEBTRENDS_ID=65.81.133.128-1177704800.29551825; $Path=/
> Cookie: $Version=0; CFID=5434634; $Path=/
> Cookie: $Version=0; CFTOKEN=90204730; $Path=/
> Content-Length: 141
> Expect: 100-continue
> Connection: keep-alive
> Accept-encoding: gzip, deflate
> Browser reload detected...
> Posting 141 bytes...
> searchstring_required=You%2Bmust%2Benter%2Ba%2Bkeyword%2Bto%2Bsearch%2Bfor.
> source=keywords
> searchstring=word1%2Bword2%2Bword3
> action=search
>
> How can I get it to keep the pluses and not substitute the "%2B"?
>
> Thanks,
> Ross
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
>