【发布时间】: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