使用Resharp访问本地服务器 [英] Accesing local server using Resharp

查看:76
本文介绍了使用Resharp访问本地服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现 searchView ,但是在此之前,我想成功地到达我的本地rest api(使用asp.net核心编写).我发现了一个名为 RestSharp 的软件包,这似乎使使用rest api非常简单.现在,我一直无法从Xamarin.Android应用程序访问我的api.我正在使用片段,该片段利用Google地图,在 OnCreateView 生命周期方法中,我正在调用 addData ,它应该可以到达我的api:

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
}

根据我如何从我的android设备访问我的本地REST api?,可以使用10.0.2.2:PORT访问我的机器localhost:PORT.但这似乎并不会触发rest api解决方案内部的断点(已通过Postman测试).

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

推荐答案

已通过删除启用SSL"解决在Debug->下的服务器属性上Web服务器设置.而且10.0.0.2应该用于从Android应用程序访问本地服务器,有关IOS的更多详细信息以及使用https使用api的信息,请参见此处:

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

这篇关于使用Resharp访问本地服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆