Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

HttpClient on some Android Devices not working?

Hi--

I have an Xamarin Android app that uses HttpClient -- on most devices, it works without any issues. However, there are at least two users with support tickets that have near identical issues that I cannot reproduce. The connection either appears to allow between 0 and 2 requests go through, and the next one will hang forever as near as I can tell.

It is configured for AndroidClientHandler and uses the Native TLS 1.2 SSL/TLS -- not much special in the code:

`
var request = new HttpRequestMessage( HttpMethod.Get, url );

                var req = client.SendAsync( request );
                req.Wait();
                using ( HttpResponseMessage response = req.Result ) {
                    using ( HttpContent content = response.Content ) {
                        if ( response.IsSuccessStatusCode ) {
                            Task<string> data = content.ReadAsStringAsync();
                            data.Wait();
                            return data.Result;
                        } else {
                            Task<string> data = content.ReadAsStringAsync();
                            data.Wait();
                            string error = data.Result;
                            log.Info( "Unexpected status code: " + response.StatusCode + ": " + error );
                            exception = new WebServiceQueryException( (int) response.StatusCode, error, error );
                            throw exception;
                        }
                    }
                }

`

client is defined as:

// Shared instance... not originally done this way HttpClientHandler handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate, AllowAutoRedirect = false, MaxAutomaticRedirections = 1 }; HttpClient client = new HttpClient( handler ); client.Timeout = TimeSpan.FromSeconds( 5 * 60 );

One user indicates that if he connects the phone to his desktop via Samsung Dex, it works -- that sort of suggests some networking proxy or something; I've tried https://medium.com/@anna.domashych/httpclient-and-proxy-76835c784eab to no avail.

Running out of ideas. The users indicate that this was working OK prior to one of our last updates earlier this year which changed the target release to a minimum version of 6.0 and target of 9.0.

Any ideas on what this could be? Thanks!

Eric

Tagged:

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    My suggestion is to ask your customers which device will face this issue. And then reproduce this issue with these devices to see the specific error messages. We don't know what really happened on the customer's side if we can't reproduce this issue.
    Additionally, data.Wait(); will freeze the main thread it's better to use await there. If you use a default handler to send the request will this occur?
    My main point is to ask the customers for the environment they used to reproduce the issues.

  • EricTheriaultEricTheriault USMember ✭✭

    Thanks for the feedback -- yes, that has been done and I've tested on that hardware and asked about their software, but have yet to spot a difference -- I am sure there is, but its not yet found. Thanks.

    Eric

  • LandLuLandLu Member, Xamarin Team Xamurai

    This may be caused by different OEM devices or systems.
    So we still need more information from the customers to reproduce this issue.

Sign In or Register to comment.