从Android设备调用Web服务

时间:2014-02-19 11:29:30

标签: android web-services android-webservice

我使用在localhost:5000上运行的python flask框架在本地编写了一个Web服务,我通过编写http://localhost:5000/toi/something

从我的计算机浏览器成功运行此Web服务

现在我试图通过将它与机器连接,从我的Android设备的浏览器中调用相同的服务。 我这是第一次这样做,所以我不确定它是否有效,或者我做错了什么,但它没有显示我的Android设备上的输出。 完成后,我将在我的Android应用程序中以编程方式调用Web服务。

谢谢 ifconfig image ip for which I am getting expected result on machine ip for which I am not getting result on machine android device using 1st IP android device using 2nd IP

2 个答案:

答案 0 :(得分:5)

我认为这不会起作用,如果您将手机连接到与计算机相同的Wifi网络,则应以这种方式访问​​:

http://ipofyourcomputer:5000/toi/something/

一旦解决了这个问题,您可以尝试使用Android上的一些库,例如:

  

OkHttp - https://github.com/square/okhttp

     

android-async-http - http://loopj.com/android-async-http/

     

排球 - https://android.googlesource.com/platform/frameworks/volley

或者,如果您正在构建 REST 服务,则可以使用:

  

改造 - http://square.github.io/retrofit/

希望它有所帮助。

答案 1 :(得分:0)

关闭Windows防火墙解决了我的问题。

相关问题