从Android设备调用Web服务设备、Android、Web

2023-09-07 12:23:08 作者:Garbage

我写了一个Web服务本地使用运行于本地主机蟒蛇瓶框架:5000 ,我写运行此Web服务成功地从我的电脑浏览器的http://本地主机:5000 / TOI /某事

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

现在我想通过与机器连接到呼叫从我的Andr​​oid设备的浏览器相同的服务。 我这样做的第一次,所以我不知道是否是这样工作的,或我做错了什么,但它并没有告诉我我的Andr​​oid设备上的输出。 一旦做到这一点,我会编程在我的Andr​​oid应用程序中调用Web服务。

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

推荐答案

我不认为这会工作,如果you've有连接到相同的WiFi网络不是你的电脑,你应该访问这样的电话:

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/

在此工作了,你可以用一些在Android库的尝试,如:

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

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

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

Android的异步HTTP - http://loopj.com/android-async-http/

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

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

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

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

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

希望它帮助。