hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Becke <be...@u.washington.edu>
Subject Re: form urlencoding, was Re: URI query escapes
Date Sun, 22 Jun 2003 04:45:50 GMT
On Saturday, June 21, 2003, at 11:47 PM, Laura Werner wrote:

> I agree, as long as URLEncoder seems to work.
>
> Do you think we need to modify URI so that it uses URLEncoder to 
> encode the query part of URIs?  In cases where a client has a URL 
> string that may or may not contain query parameters, it would lead to 
> a slightly more natural API usage:
>  HttpMethod meth = new GetMethod(new URI(urlString));
> as opposed to
>  String query = null;
>  int index = urlString.indexOf('?');
>  if (index != -1) {
>    query = urlString.substring(index+1);
>    urlString = urlString.substring(0, index);
>  }
>  HttpMethod meth = new GetMethod(new URI(urlString));
>  meth.setQueryString(java.net.URLEncoder.encode(query));
> or something like that, with error checking of course.

I don't think URI should be doing any form urlencoding.  The URI spec 
does not use the concept of query params.  It just treats the entire 
query as a single entity.

Also, when creating a URI containing query params, the params must be 
encoded before the URI is generated otherwise it will not be parsable.  
For example, when creating a URI with the following query params:

Name	Value
param1	value&1
param2	value=2

If not pre-encoded, the URI would look something like 
"http://host/path?param1=value&1&param2=value=2".

Once joined together it is too late to encode.  This is why the 
HttpMethod(String) constructor assumes that all URIs are already 
encoded, as it is not possible to correctly encoded them after the fact.

Please let me know if you will be writing some code for this as I will 
take care of it tomorrow otherwise.

Mike


Mime
View raw message