Forum Xamarin.Android

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Accesing local server using Resharp

Je12emyJe12emy Member ✭✭

I am in progress of implementing a searchView but before I do that I would like to successfully reach my local rest api (written using asp.net core). I found a package named RestSharp which seems to make consuming a rest api very simple. Right now I am stuck at accessing my api from my Xamarin.Android application. I am using a fragment which makes use of google maps, at the OnCreateView lifecycle method I am calling a addData which is supposed to reach out to my api:

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Use this to return your custom view for this Fragment
            //base.OnCreateView(inflater, container, savedInstanceState);
            View view = inflater.Inflate(Resource.Layout.activity_main, container, false);
            // Initialize Views
            _listView = view.FindViewById<ListView>(Resource.Id.searchList);
            _seachView = view.FindViewById<SearchView>(Resource.Id.searchView);
            addData();
            return view;
        }
        public void addData() {
            var client = new RestClient("http://10.0.2.2:44392");
            var request = new RestRequest("/api/Ruta", DataFormat.Json);
            var response = client.Get(request);
            Console.WriteLine(response.Content);
        }
        // More code
}

According to How can I access my local REST api from my android device?, 10.0.2.2:PORT can be used to access my machines localhost:PORT. But this does not seem to trigger a break point inside the rest api's solution (Already tested with Postman).

Sign In or Register to comment.