Skip to content Skip to sidebar Skip to footer

How To Fix A "java.io.ioexception: Unexpected End Of Stream On Connection" Exception In Httpclient On .netstandard

I have been scratching my head with this one for a while. I'm building an Android app in Xamarin and I have a login POST request that mostly works, but will occasionally recieve th

Solution 1:

After following the information in this link: https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/http-stack?tabs=macos

And changing my HTTPHandler to the native android handler:

The Xamarin.Android HttpClient configuration is in Project Options > Android Options, then click the Advanced Options button.

These are the recommended settings for TLS 1.2 support:

Visual Studio Android Options

enter image description here

The one extra bit I missed was:

Projects must reference the System.Net.Http assembly.

Make sure your project references System.Net.Http otherwise it will still use OKHttp

Solution 2:

You can just go the Android Project > Properties > AssemblyInfo.cs file. Open the AssemblyInfo file and add the following line at the end:

[assembly: Application(UsesCleartextTraffic = true)]

This helped me solve my problem. I hope it helps you also

Solution 3:

I was having the same issue and been tracing for this fix. My project reference to System.Net.Http. I was changing my HTTPHandler to the native android handler when I got this exception but getting kinda similar system exception when using a different HTTPHandler. I tried a lot of suggestions and finally fixes the issue by using https in my base URL. Here's my reference: https://github.com/square/okhttp/issues/1517#issuecomment-560486265

IMO, the fix might be different in each case, so you might want to try other suggestions.

Post a Comment for "How To Fix A "java.io.ioexception: Unexpected End Of Stream On Connection" Exception In Httpclient On .netstandard"