问题描述
我正在Android Studio上开发一个Android应用程序,并尝试调试.net core
API。
我尝试过:
- 10.2.0.2 IP地址
- 我的本地WI-FI IP地址
- 仿真器和连接的设备连接到同一WI-FI
所以我的问题是如何从仿真器和连接的设备调试本地API?
在最新更新中仍然有可能吗?
解决方法
我通过在调试期间忽略 ssl 错误来解决它。这可以通过使用不同的 HttpClient 实例来完成,如下所示。
#if DEBUG
HttpClientHandler handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback = (message,cert,chain,errors) =>
{
return true;
};
HttpClient httpClient = new HttpClient(handler);
#else
HttpClient httpClient = new HttpClient();
#endif
此外,您还需要使用 ip 和 port 而不是 localhost 来运行您的 api。
请参阅以下链接中的“绕过证书安全检查”部分。 https://docs.microsoft.com/en-us/xamarin/cross-platform/deploy-test/connect-to-local-web-services#create-a-development-certificate