xamarin.forms httpclient.PostAsync not working on xamarin.ios (ios 14) but works on xamarin.android

579 Views Asked by At

Below is my Code

try
        { 

var json = JsonConvert.SerializeObject(dtr);
        var content =  new StringContent(json, Encoding.UTF8, "application/json");

            //This line below works on android but not on ios 14 devices , no exception return , nothing happened.

            var  response = await client.PostAsync("edtrapi/api/edtr", content);
             
            string res = await response.Content.ReadAsStringAsync();

            return Convert.ToInt32(res);
            
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message.ToString());
            return 0;
        }

xamarin.ios build

xamarin.ios info.plist web api https

1

There are 1 best solutions below

3
On

I guesss you are testing with Http request.

Actually from iOS9, Http request is not allowed by default, since it is not safe, Https is the recommeded way .

To enable Http , you can set ATS in info.plist .

Or add exceptions for specific domains .

Refer to https://stackoverflow.com/a/35884843/8187800 .