artiya4u / google-http-java-client

Automatically exported from code.google.com/p/google-http-java-client
0 stars 0 forks source link

Special characters in http request URL parameters are ignored #202

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Version of google-http-java-client (e.g. 1.5.0-beta)?
1.13.0-beta. Also found in 1.11.0-beta.

Java environment (e.g. Java 6, Android 2.3, App Engine)?
All.

Describe the problem.
Using HttpRequestFactory to build a POST request and execute it fails if the 
POST request contains form parameters with special characters.

For example:
final Map<String, String> params = new HashMap<String, String>();
                params.put("username", username);
        params.put("password", password); 
final HttpContent content = new UrlEncodedContent(params);
final String baseURL = "http://www.something.com";
final GenericUrl url = new GenericUrl(baseURL);
url.putAll(params);
final HttpRequest req = hrf.buildPostRequest(url, content);
final HttpResponse resp = req.execute();    <----- always fails

Here the password field actually contains special characters (eg: 
password123;{} ). It seems most special characters are ignored by the API, 
resulting in a IOException (401 from the server) since the correct password 
wasn't provided by the client. So basically instead of server receiving 
"password123;{}", it only gets "password123".  Also tried to UTF-8 encode them 
without no effect. This is critical as it impacts login to the server.  

How would you expect it to be fixed?
Allow special characters to be sent and not ignored in the Http request for 
authorization.

Original issue reported on code.google.com by gyourm...@gmail.com on 24 Feb 2013 at 9:47

GoogleCodeExporter commented 9 years ago
By design: UrlEncodedContent escapes special characters.  Your server needs to 
unescape them when it parses the content.

Unit tests added:
https://codereview.appspot.com/7377060/

Original comment by yan...@google.com on 27 Feb 2013 at 4:28