【问题标题】:Localhost restAPI access from Android Studios on physical device using cable使用电缆从物理设备上的 Android Studios 访问 Localhost restAPI
【发布时间】:2022-01-27 10:58:56
【问题描述】:

我在 DjangoREST 中创建了一个 API,它在我的本地主机上运行,​​地址为 http://localhost:xxxxx/api/allproduct。

我还在 Futter 中创建了一个 Android 应用,使用 Android Studio 并尝试访问上述 API。我正在使用数据线(不是通过模拟器)调试我的应用程序。我无法访问 API。 我必须使用不在模拟器上的电缆测试应用程序,请提供任何线索。

【问题讨论】:

标签: flutter api android-studio localhost android-networking


【解决方案1】:

我使用名为ngrok 的代理服务。安装后,你可以像这样运行它:

ngrok http 8080(假设您的 localhost 在端口 8080 上提供服务)

它将创建一个隧道,对 HTTP 和 HTTPS 都适用(因此 iOS 设备不会因为不安全的协议而拒绝请求)

然后,您只需将您的 http://localhost 替换为 ngrok 中的主机,如下所示:

http://xxxx-xxxx-xxx-...-xxxx.ngrok.io

它甚至会为您提供一个 Web 界面,您可以访问该界面来查看流量:

http://127.0.0.1:4040

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-22
    • 2015-06-27
    • 2015-07-13
    • 2013-02-24
    • 1970-01-01
    • 2019-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多