我正在运行的本地计算机上运行Web服务localhost:54722.
我想从Android模拟器中运行的应用程序调用该服务.
我读到10.0.2.2在应用程序中使用将访问localhost,但它似乎也不适用于端口号.它说HttpResponseException: Bad Request.
我正在使用
public static String getLocalIPAddress(WifiManager wm){
return Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
}
Run Code Online (Sandbox Code Playgroud)
获取执行设备的IP地址.如果设备连接到"公共"wlan网络,并且设备连接到由其他Android设备通过热点托管的wifi网络,则工作正常.如果设备未连接到任何wifi网络,则返回"0.0.0.0"(正确).但是,如果设备通过提供热点来托管wifi网络,则该方法仍然返回"0.0.0.0".如何在"自己的wifi网络"中获取热点提供设备的真实IP地址?
感谢和问候
我可以使用 localhost 通过 http 测试 serviceworkers,但我想在移动浏览器上测试。因为它是一个单独的设备,所以我不能使用 localhost,所以我使用了 PC 的名称。所以现在我需要使用 https,这会导致我的 Service Worker 出现 SSL 相关错误:
Uncaught (in promise) DOMException: Failed to register a ServiceWorker for scope (' https://xxx:5500/app/ ') with script (' https://xxx:5500/app/service_worker.js '): An SSL获取脚本时发生证书错误。
我已正确配置 liveServer 以使用自签名证书,并且已成功启用“edge://flags/#unsafely-treat-insecure-origin-as-secure”,但这还不够。
我还担心如何在移动设备上测试 PWA,因为我认为我无法在移动设备上使用“不安全”功能。我认为这是一个常见的情况,但我没有找到任何答案。
android ×3
android-wifi ×1
ip ×1
localhost ×1
networking ×1
openssl ×1
port ×1
self-signed ×1
wifimanager ×1