【问题标题】:Debug local APIs from emulator or connected device从模拟器或连接的设备调试本地 API
【发布时间】:2020-08-17 20:06:58
【问题描述】:

我知道这个问题确实被问了很多,但没有一个答案对我有用。

我正在 Android Studio 上开发一个 Android 应用程序,并尝试调试我的 .net core API。

我试过了:

  • 10.0.2.2 IP 地址
  • 我的本地 WI-FI IP 地址
  • 模拟器和连接的设备连接到同一个 WI-FI

所以我的问题是如何从模拟器和连接的设备调试我的本地 API?

在最新更新中这仍然可能吗?

【问题讨论】:

  • 您想在 Visual Studio 中从您连接的 android 设备调试 .net core api吗?
  • 是的,这正是我想要的@PerryQian-MSFT
  • 你应该在VS上创建一个android应用项目,然后按照this link's solution从连接的设备调试这样的本地api。
  • 尝试在管理员模式下运行您的 API

标签: android android-studio debugging visual-studio-debugging


【解决方案1】:

我通过在调试期间忽略 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 和端口而不是 localhost 来运行您的 api。

请参阅以下链接中的“绕过证书安全检查”部分。 https://docs.microsoft.com/en-us/xamarin/cross-platform/deploy-test/connect-to-local-web-services#create-a-development-certificate

https://www.youtube.com/watch?v=HW_P3Eb-XWU

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-25
    • 2021-08-30
    相关资源
    最近更新 更多