将 Android 设备连接到本地主机上的 Web 服务 [英] Connect an Android Device To a Web Service on Local Host

查看:28
本文介绍了将 Android 设备连接到本地主机上的 Web 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为 Android 应用程序实现了一个 Web 服务.Web 服务在我的本地主机 (192.168.1.2) 上运行.使用 Android 模拟器,我成功连接到 Web 服务.我尝试使用调试模式将我的 Android 设备连接到 Web 服务,但没有成功.所以我的问题是,是否可以在不使用真实 IP 的情况下将 Android 设备连接到在我的本地主机(192.168.1.2)上运行的这个 Web 服务?

I implemented a web service for an Android application. The web service is running on my local host (192.168.1.2). Using the Android emulator I succeeded to connect to web service. The I tried to connect my Android device using debugging mode to web service but it didn't work. So my question is if it is possible to connect an Android device to this web service that is running on my local host (192.168.1.2) without using a real IP ?

推荐答案

google支持的更简单的方法!

  • 将手机通过usb连接到电脑并开启usb调试
  • 在您的计算机上打开 Chrome 浏览器并准确输入以下地址:chrome://inspect/#devices
  • 现在您可以通过端口转发按钮将您的计算机端口链接到您的设备端口.在我的计算机上,我在地址 localhost:61437 上有服务,我只是将它链接到设备的 8081 端口.记得勾选启用端口转发"复选框
  • It's much simpler way supported by google!

    • Connect your phone via usb to computer and enable usb debugging
    • On your computer open Chrome browser and type exactly this address: chrome://inspect/#devices
    • Now you can link your computer port to your device port by port forwarding button. On my computer I have service on address localhost:61437 and I just linked it to device's 8081 port. Remeber to check 'Enable port forwarding' checkbox
      • 我电脑上的服务屏幕 (localhost:61437)

      使用相同服务 (localhost:8081) 的移动浏览器屏幕.就是这样.您也在您的应用程序中使用此服务地址

      screen from my mobile browser with the same service ( localhost:8081). And that's it. Also you use this service address in your application

      这篇关于将 Android 设备连接到本地主机上的 Web 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆