0

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

ToolmakerSteve
  • 18,547
  • 14
  • 94
  • 196
Dodong
  • 39
  • 1
  • 7
  • are you using the actual IP of your server, or localhost/loopback? – Jason Jan 21 '22 at 13:27
  • hi jason , actually i have tried using the ip of my host. and i also tried the public domain name. but only the get method is working , the post method is having the problem. – Dodong Jan 24 '22 at 00:56
  • if a GET works, then it's not a connectivity problem. Is your request reaching the server? Have you checked the server logs? – Jason Jan 24 '22 at 01:00
  • actually i tried to debug the post method on the server but nothing happened, it does not hit the breakpoint . the request does not reach the server. it only happens on ios , but on android it works perfectly. – Dodong Jan 24 '22 at 01:17
  • the request may be hitting the server but not be routed to your endpoint. Just to double-check, the GET request DOES work on iOS? Have you tried using the different HTTP client options? – Jason Jan 24 '22 at 01:22
  • yes it does , the get request works on ios. Just the post request wont work. – Dodong Jan 24 '22 at 01:27
  • i also tried NSAllowsArbitraryLoads – Dodong Jan 25 '22 at 06:27

1 Answers1

0

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 .

ColeX
  • 14,062
  • 5
  • 43
  • 240
  • hi Colex, actually im using https on our server. and i already uses that setting in the info.plist , but still wont allow post. im using ios software version 14.8.1 but its working on simulator ios version 13.1 – Dodong Jan 25 '22 at 02:57
  • i also try NSAllowsArbitraryLoads – Dodong Jan 25 '22 at 06:27
  • It's really weird, consider raising this issue on github : https://github.com/xamarin/xamarin-macios/issues – ColeX Jan 25 '22 at 06:31