[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-1253?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Gary Gregory updated HTTPCLIENT-1253:
-------------------------------------

    Summary: URIBuilder setParameter() method could exceed the HTTP header 
size.    (was: URIBuilder setParameter() method could exceed the http header 
size.  )
    
> URIBuilder setParameter() method could exceed the HTTP header size.  
> ---------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1253
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1253
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>          Components: HttpClient
>    Affects Versions: 4.2.1
>            Reporter: Alan T Chen
>            Priority: Minor
>             Fix For: 4.3 Alpha1
>
>
> Maybe the URIBuilder is not designed with POST vs GET in mind so it will 
> construct the form parameters into the header by default.  However, this is 
> an issue when the content exceeds what the header allows.
> the following code will cause issues when the length of the parameters exceed 
> the http header.
>                 // TODO: need to pass in the target host/port
>                 URIBuilder builder = new URIBuilder();
>                 
> builder.setScheme("http").setHost(targetHost).setPort(targetPort).setPath(s);
>                 Map<String, String> params = 
> getRequestParameters(servletRequest);
>                 for (String key : params.keySet())
>                 {
>                     String value = params.get(key);
>                     builder.setParameter(key, value);
>                 }
>                 httpPost = new HttpPost(builder.build());
> ======== 
> I have to fix it by using the httpPost.setEntity() method to ensure the form 
> post will insert all parameters into the body of the http post request 
> instead of the header.
>                 httpPost = new HttpPost(builder.build());
>                 Map<String, String> params = 
> getRequestParameters(servletRequest);
>                 List<NameValuePair> nameValuePairs = new 
> ArrayList<NameValuePair>(20);
>                 // add the params
>                 for (String key : params.keySet())
>                 {
>                     String value = params.get(key);
>                     // only add the http param if both key and value are not 
> null
>                     if( key != null && value != null )
>                         nameValuePairs.add(new BasicNameValuePair(key, 
> value));
>                 }
>                 httpPost.setEntity( new UrlEncodedFormEntity(nameValuePairs) 
> );

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org

Reply via email to