How to fix a “java.io.IOException: unexpected end of stream on Connection” exception in HTTPClient on .NetStandard

后端 未结 3 1485
北恋
北恋 2020-12-10 07:39

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 re

相关标签:
3条回答
  • 2020-12-10 08:04

    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

    0 讨论(0)
  • 2020-12-10 08:08

    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

    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

    0 讨论(0)
  • 2020-12-10 08:29

    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.

    0 讨论(0)
提交回复
热议问题