alexrainman / ModernHttpClient

ModernHttpClient
MIT License
126 stars 27 forks source link

DangerousAllowInsecureHTTPLoads = true does not work if android:targetSdkVersion="28" #52

Closed akondratiuk1 closed 4 years ago

akondratiuk1 commented 4 years ago

Demo.Droid project ModernHttpClient: 3.3.4 VS 2019

steps to reproduce:

  1. set android:targetSdkVersion="28" in android manifest
  2. configure MainViewModel:
public class MainViewModel
{
    public async Task Get()
    {
        var handler = new NativeMessageHandler(false, new TLSConfig
        {
            DangerousAllowInsecureHTTPLoads = true
        });
        var client = new HttpClient(handler);
        var url = new Uri("http://gorest.co.in/public-api/users?_format=json&access-token=ZpvESa-uwxDolSDuCdONfCBnq1NU1nCKkP5z");
        var response = await client.GetAsync(url);
        Debug.WriteLine(response.Content);
    }
}
  1. run

Expected result: request successful Actual result: got "System.Net.Http.HttpRequestException: 'CLEARTEXT communication to gorest.co.in not permitted by network security policy'"

error

alexrainman commented 4 years ago

I need to run some tests.

alexrainman commented 4 years ago

There's nothing i can do about this programmatically. Check this link and use the solution that better suit your needs: https://medium.com/@son.rommer/fix-cleartext-traffic-error-in-android-9-pie-2f4e9e2235e6

alexrainman commented 4 years ago

Will provide a fix for this in next release but providing some configuration in the AndroidManifest.xml will be required.

akondratiuk1 commented 4 years ago

thanks!