Bug 61025 - AndroidHttpClient isn't properly encoding urls, causing Bad Request (400) errors
Summary: AndroidHttpClient isn't properly encoding urls, causing Bad Request (400) errors
Status: RESOLVED DUPLICATE of bug 60473
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 8.1 (15.5)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2017-12-07 16:16 UTC by Justin Toth
Modified: 2017-12-07 16:33 UTC (History)
1 user (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Justin Toth 2017-12-07 16:16:02 UTC
I posted this in another resolved ticket, but no one responded so I'm posting a new ticket for visibility. I just switched from ModernHttpClient to AndroidHttpClient (because ModernHttpClient doesn't support HTTP/2), and now I'm seeing the following issue. 

If I call our api with an encoded space in the url, it works fine:


However if I add in an encoded comma, it gives a 400 bad request error:


If I don't encode the comma, it works:

https://mobileapi-int.narrpr.com/v14/searches/properties/Irvine, CA

However, then I get into trouble if trying to use other symbols. For example when trying to use a #, both of these error:

https://mobileapi-int.narrpr.com/v14/searches/properties/20 pine bark ct #20 cockeysville md


The interesting thing is that if I debug the request and response, when I pass in the request uri (which has an AbsolutePath of "/v14/searches/properties/irvine%2C%20ca") to the http client's GetAsync method, when I check the erroring task's Result.RequestMessage.RequestUri.AbsolutePath it is set to  "/v14/searches/properties/irvine%252C%20ca". So it looks like Xamarin is updating "%2C%20" to "%252C%20", which isn't right and causes the bad request.

public Task<QueryResponse<TResult>> GetAsync<TResult> (UriBuilder uriBuilder, CancellationToken cancellationToken) {
            var uri = GetUri (uriBuilder);
            var antecedent = base.GetAsync (uri).ObserveFailures ();
            return antecedent.ContinueWith (a => {
                var response = new QueryResponse<TResult> (a.Result.StatusCode);
                if (!a.Result.HasServerError (response, uri.AbsolutePath))
                    response.Response = ReadResponseContent<TResult> (a.Result);
                return response;
            }, cancellationToken).ObserveFailures ();

I could really use help on this, as it's blocking us from our release.
Comment 1 Justin Toth 2017-12-07 16:33:34 UTC
Actually it looks like this bug was already identified (https://bugzilla.xamarin.com/show_bug.cgi?id=60473) and fixed (https://github.com/xamarin/xamarin-android/commit/e6b85552ef2a9bc6e73f36fbab0ab94682f5dd65). I'm adding the "?dummy=yeah" hack to my urls for now, any idea when this will make it into a Xamarin.Android release?

*** This bug has been marked as a duplicate of bug 60473 ***