Android HttpClient 通过 USB 向主机发送请求

发布于 2024-11-17 14:31:41 字数 359 浏览 3 评论 0原文

我有一个在通过 USB 连接到主机的手机上运行的 Android 应用程序。手机将始终连接到机器,我需要向机器发出 HTTP 请求。在模拟器中工作,我可以使用 IP 地址 10.0.2.2 访问计算机上运行的网络服务器,并且工作正常。然而,在手机上运行相同的应用程序时,我收到 Network unreachableSocketException。手机中没有 SIM 卡,也没有 WiFi 连接,我需要 HTTP 请求通过 USB 发送到计算机。这有可能吗?如果是这样,我做错了什么。

我使用的是标准 HttpClient 代码,没有什么特别的,如果我使用 wifi 连接在手机上运行它,它绝对可以正常工作,所以我知道这不是问题。

I have an Android app running on a phone that's connected to a host machine over USB. The phone will always be connected to the machine and I need to go an HTTP request to the machine. Working in the emulator, I can access the webserver running on the computer using the IP address of 10.0.2.2 and that works fine. However running the same app on the phone, I get a SocketException of Network unreachable. The phone doesn't have a SIM card in it, nor does it have a wifi connection, I need the HTTP request to just go over USB to the computer. Is this at all possible? If so, what am I doing wrong.

I'm using standard HttpClient code, nothing special, which works absolutely fine if I run it on the phone using a wifi connection, so I know that's not the problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

醉生梦死 2024-11-24 14:31:41

我最终放弃了这个,基本上使用 adb 在手机上轮询我想要从计算机上获取的新内容。

I ended up abandoning this and basically polling the phone for the new content I wanted from the computer using adb.

素衣风尘叹 2024-11-24 14:31:41

反向网络共享!不确定它是否有效。我从来没有尝试过。该线程可能会有所帮助:

https://android.stackexchange.com /questions/2298/如何通过 USB 设置反向网络共享

Reverse Tethering! not sure if it works. I never tried it. This thread might help:

https://android.stackexchange.com/questions/2298/how-to-set-up-reverse-tethering-over-usb

彻夜缠绵 2024-11-24 14:31:41

这个 Android 应用程序 + Windows 主机应用程序应该可以解决问题:

http://www.codeproject.com /KB/android/UsbPortForwarding.aspx

This Android app + Windows host app should do the trick:

http://www.codeproject.com/KB/android/UsbPortForwarding.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文