Author: sebb
Date: Wed Apr 18 13:31:24 2007
New Revision: 530147

URL: http://svn.apache.org/viewvc?view=rev&rev=530147
Log:
Bug 42156 - HTTPRequest HTTPClient incorrectly urlencodes parameter value in 
POST

Modified:
    
jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
    jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml

Modified: 
jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java?view=diff&rev=530147&r1=530146&r2=530147
==============================================================================
--- 
jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
 (original)
+++ 
jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
 Wed Apr 18 13:31:24 2007
@@ -361,8 +361,41 @@
                     PropertyIterator args = getArguments().iterator();
                     while (args.hasNext()) {
                         HTTPArgument arg = (HTTPArgument) 
args.next().getObjectValue();
-                        post.addParameter(arg.getName(), arg.getValue());
+                        // The HTTPClient always urlencodes both name and 
value,
+                        // so if the argument is already encoded, we have to 
decode
+                        // it before adding it to the post request
+                        String parameterName = arg.getName();
+                        String parameterValue = arg.getValue();
+                        if(!arg.isAlwaysEncoded()) {
+                            // The value is already encoded by the user
+                            // Must decode the value now, so that when the
+                            // httpclient encodes it, we end up with the same 
value
+                            // as the user had entered.
+                            String urlContentEncoding = contentEncoding;
+                            if(urlContentEncoding == null || 
urlContentEncoding.length() == 0) {
+                                // Use the default encoding for urls 
+                                urlContentEncoding = 
EncoderCache.URL_ARGUMENT_ENCODING;
+                            }
+                            parameterName = URLDecoder.decode(parameterName, 
urlContentEncoding);
+                            parameterValue = URLDecoder.decode(parameterValue, 
urlContentEncoding);
+                        }
+                        // Add the parameter, httpclient will urlencode it
+                        post.addParameter(parameterName, parameterValue);
                     }
+                    
+/*
+//                    // Alternative implementation, to make sure that 
HTTPSampler and HTTPSampler2
+//                    // sends the same post body.
+//                     
+//                    // Only include the content char set in the content-type 
header if it is not
+//                    // an APPLICATION_X_WWW_FORM_URLENCODED content type
+//                    String contentCharSet = null;
+//                    
if(!post.getRequestHeader(HEADER_CONTENT_TYPE).getValue().equals(APPLICATION_X_WWW_FORM_URLENCODED))
 {
+//                        contentCharSet = post.getRequestCharSet();
+//                    }
+//                    StringRequestEntity requestEntity = new 
StringRequestEntity(getQueryString(contentEncoding), 
post.getRequestHeader(HEADER_CONTENT_TYPE).getValue(), contentCharSet);
+//                    post.setRequestEntity(requestEntity);
+*/                    
                 }
                 else {
                     // Just append all the parameter values, and use that as 
the post body

Modified: jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml?view=diff&rev=530147&r1=530146&r2=530147
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml (original)
+++ jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml Wed Apr 18 13:31:24 2007
@@ -208,6 +208,7 @@
 <li>Bug 42019 - Content type not stored in redirected HTTP request with 
subresults</li>
 <li>Bug 42057 - connection can be null if method is null</li>
 <li>Bug 41518 - JMeter changes the HTTP header Content Type for POST 
request</li>
+<li>Bug 42156 - HTTPRequest HTTPClient incorrectly urlencodes parameter value 
in POST</li>
 </ul>
 
 <h3>Version 2.2</h3>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to