Bug 42156 - HTTPRequest HTTPClient incorrectly urlencodes parameter value in POST
HTTPRequest HTTPClient incorrectly urlencodes parameter value in POST
Status: RESOLVED FIXED
Product: JMeter
Classification: Unclassified
Component: HTTP
2.2
Other other
: P2 normal (vote)
: ---
Assigned To: JMeter issues mailing list
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2007-04-18 03:58 UTC by Alf Hogemark
Modified: 2007-04-18 13:37 UTC (History)
0 users



Attachments
Suggested patch (38.33 KB, patch)
2007-04-18 04:09 UTC, Alf Hogemark
Details | Diff
Updated suggested patch (38.22 KB, patch)
2007-04-18 04:12 UTC, Alf Hogemark
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alf Hogemark 2007-04-18 03:58:15 UTC
In the HTTP Request GUI, there is a checkbox for each parameter value, "Encode?".
Even if this is unchecked, the HTTP Request using HTTP Client urlencodes the
value when doing a HTTP POST request, which is incorrect.

The reason is that the HTTPClient PostMethod class addParameter method, which is
called in HTTPSampler2.java, assumes that the value is not alread URL encoded.
So the HTTPClient PostMethod always urlencodes the parameter names and values
before they are sent.

So if you have a parameter named test, with value "%2Ftest%3D", and do a POST
request, the POST body will contain "%252Ftest%253D", because the already
urlencoded value is urlencoded once more.

If you are using a HTTP Request (i.e the HTTPSampler.java), you will see that
"%2Ftest%3D" is sent, because the getQueryString of HTTPSamplerBase takes into
consideration the value of httpargument.isAlwaysEncoded().
Comment 1 Alf Hogemark 2007-04-18 04:09:30 UTC
Created attachment 19986 [details]
Suggested patch

This patch urldecodes parameter value if the httpargument.isAlwaysEncode is
false, so that when it is added to the httpclient postmethod, where it is
urlencoded, the value will be correct.

There is also an commented out section, which uses the
HTTPSamplerBase.getQueryString to construct the post body. If this alternative
is used, then HTTPSampler and HTTPSampler2 will always send the same POST body.

I do not know which alternative you prefer.

The patch also contains more unit tests for
TestHTTPSamplersAgainstHttpMirrorServer, it contains the new tests suggested in
patch for bug 42139, plus some more, to expose this bug.
So if this patch for this bug is applied, then bug 42139 should just be closed.

If only the unit tests are applied, then you will see that one test will fail
for HTTPSampler2, the one with 
titleValue =
"%2FwEPDwULLTE2MzM2OTA0NTYPZBYCAgMPZ%2FrA%2B8DZ2dnZ2dnZ2d%2FGNDar6OshPwdJc%3D";
Comment 2 Alf Hogemark 2007-04-18 04:12:59 UTC
Created attachment 19987 [details]
Updated suggested patch

I just had to remove to System.out.println lines, which accidential made it
into my first suggested patch.
Comment 3 Sebb 2007-04-18 13:37:33 UTC
Thanks! Applied to SVN r530147 - I ignored the 
TestHTTPSamplersAgainstHttpMirrorServer part as I'd already applied bug 42139.