【问题标题】:Accesing local server using Resharp使用 Resharper 访问本地服务器
【发布时间】:2020-11-03 08:07:21
【问题描述】:

我正在实施searchView,但在此之前,我想成功访问我的本地rest api(使用asp.net core 编写)。我发现了一个名为 RestSharp 的包,它似乎让使用 rest api 变得非常简单。现在我被困在从我的 Xamarin.Android 应用程序访问我的 api 上。我正在使用一个使用谷歌地图的片段,在OnCreateView 生命周期方法中我调用了一个addData,它应该可以访问我的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
}

根据How can I access my local REST api from my android device?,10.0.2.2:PORT 可以用来访问我的机器localhost:PORT。但这似乎并没有在其余 api 的解决方案中触发断点(已经用 Postman 测试过)。

【问题讨论】:

  • 用visual studio运行api,使用地址localhost:Port断点会被命中。
  • 已经试过了,断点被忽略了。可能与以非异步方式触发请求有关吗?
  • 确保在visual studio项目中运行在调试模式下
  • 以调试模式启动(显示的断点与我的api项目无关):i.imgur.com/azxhgb5.png

标签: android asp.net-core android-fragments xamarin.android restsharp


【解决方案1】:

通过在“调试”->“Web 服务器设置”下的服务器属性中删除“启用 SSL”来解决。 并且应该使用 10.0.0.2 从 Android 应用程序访问本地服务器,有关 IOS 和使用 https 使用 api 的更多详细信息,请在此处查看:https://docs.microsoft.com/en-us/xamarin/cross-platform/deploy-test/connect-to-local-web-services

【讨论】:

    猜你喜欢
    • 2014-09-16
    • 2018-10-21
    • 2014-09-03
    • 2012-10-10
    • 1970-01-01
    • 2011-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多