Calling web service from android device

拥有回忆 提交于 2019-12-04 03:46:50

问题


I have written a web service locally using python flask framework which runs on localhost:5000 , I run this web service successfully from my computers browser by writing http://localhost:5000/toi/something

Now I am trying to call same service from the browser of my android device by connecting it with the machine. I am doing this for the first time so I am not sure whether it works this way or I am doing something wrong but it does not show me the output on my android device. Once this is done I will be calling the web service programatically in my android application.

Thank You


回答1:


I don't think that will work, if you´ve got the phone connected to the same Wifi network than your computer you should access it this way:

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

Once this works out you can try it with some of the libraries available on Android like:

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

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

Volley - https://android.googlesource.com/platform/frameworks/volley

Or if you're building a REST service you can use:

Retrofit - http://square.github.io/retrofit/

Hope it helps.




回答2:


My problem solved by turning off windows firewall.



来源:https://stackoverflow.com/questions/21879151/calling-web-service-from-android-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!