Accesing local server using Resharp

最后都变了- 提交于 2021-02-11 13:41:54

问题


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).


回答1:


Solved by removing "Enable SSL" on the server's properties under Debug -> Web Server Settings. And 10.0.0.2 should be used to access a local server from the Android application, for more details for IOS and consuming the api with https check here: https://docs.microsoft.com/en-us/xamarin/cross-platform/deploy-test/connect-to-local-web-services



来源:https://stackoverflow.com/questions/62887536/accesing-local-server-using-resharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!