Accessing Localhost RestAPI in Android Emulator

Hi,

I’m trying to access Localhost RestAPI (http://localhost:9001/api/Member/Login) from Xamarin form on Android Emulator. But its throwing errors like “One or more errors occurred. (Response status code does not indicate success: 400 (Bad Request).)”

The Local host RestAPI url is returning results when it is accessed through development machine browser but in Android emulator it’s failing.

I tried with url such as -  http://10.0.2.2:9001/api/Member/Login and with my computer’s IP address as http://192.168.0.105:9001/api/Member/Login but nothing is working. Can you please check on this front?


Code: Test_UC.cs of Test_UC.xaml

using Xamarin.Forms;

using System.Net.Http;

namespace MobileApp.Views.Test

{    

    public partial class Test_UC : ContentView

    {

        public Test_UC()

        {

            InitializeComponent();

                        

            string aaa = "Login?Input_JSON={'CRUD_Type': 2}";


            object Obj1 = Invoke_RESTAPI("http://localhost:9001/api/Member/", aaa);            

        

        }


        static object Invoke_RESTAPI(string BaseAddress, string Request_URI)

        {

            object Return_Value = null;

            using (var client = new HttpClient())

            {                

                string _URL = BaseAddress + Request_URI;

                

                var responseTask1 = client.GetStringAsync(_URL);

                var responseTask1_Result = responseTask1.Result;

            }


            return Return_Value;

        }


    }

}

 


1 Reply 1 reply marked as answer

SP Sakthivel Palaniyappan Syncfusion Team June 2, 2020 01:24 PM UTC


Marked as answer
Loader.
Up arrow icon