locked
Can't call API from Xamarin Forms RRS feed

  • Question

  • User370434 posted

    Hallo,

    I installed my API in my development machine under IIS. I can call the API using a browser. Now i want to call it via my Xamarin Forms app(using VS 2017 and a android phone connected via USB), but it doesn't work. This is my code: protected async override void OnAppearing() { base.OnAppearing(); await RefreshDataAsync(); } public async Task RefreshDataAsync() { Uri uri = new Uri(string.Format("http://192.168.1.85:8080/api/Loods", string.Empty)); HttpResponseMessage response = await client.GetAsync(uri); if (response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); } } When is set a breakpoint on the 'RefreshDataAsync' method, it disappears on this line: HttpResponseMessage response = await client.GetAsync(uri); The app starts without any results or exceptions. I also opened the port 8080 via Windows Firewall.

    Wednesday, July 1, 2020 3:13 PM

Answers

  • User74 posted

    @KeBi said:

    @JohnH said: Can you open that url on the Android web browser? It is a get request so should return something.

    Yes, i can open the URL on my device browser and see the result of my get method.

    Remove the string.format from the new Uri. I doubt it will make a difference but will clean up the code.

    Wrap the content of the method in a try catch and put a breakpoint within the catch, see if anything is being thrown.

    Put a breakpoint on the if success line and see if it gets that far.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, July 2, 2020 11:02 AM

All replies

  • User74 posted

    Can you open that url on the Android web browser? It is a get request so should return something.

    Wednesday, July 1, 2020 8:08 PM
  • User371688 posted

    Yes, you can first open the on the Android web browser to see if there is some result.

    Besides, could you please post the full log when you encounter this question? It will help us to address this question.

    Thursday, July 2, 2020 7:45 AM
  • User370434 posted

    @jezh said: Yes, you can first open the on the Android web browser to see if there is some result.

    Besides, could you please post the full log when you encounter this question? It will help us to address this question.

    Hello Jezh, I can open the URL on my device browser and see the result of my get method. What do u mean with 'full log' ? (newbie here)

    Thursday, July 2, 2020 9:01 AM
  • User370434 posted

    @JohnH said: Can you open that url on the Android web browser? It is a get request so should return something.

    Yes, i can open the URL on my device browser and see the result of my get method.

    Thursday, July 2, 2020 10:58 AM
  • User74 posted

    @KeBi said:

    @JohnH said: Can you open that url on the Android web browser? It is a get request so should return something.

    Yes, i can open the URL on my device browser and see the result of my get method.

    Remove the string.format from the new Uri. I doubt it will make a difference but will clean up the code.

    Wrap the content of the method in a try catch and put a breakpoint within the catch, see if anything is being thrown.

    Put a breakpoint on the if success line and see if it gets that far.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, July 2, 2020 11:02 AM