Flutter应用程序无法与其他网络上的服务器通信

时间:2020-05-06 15:50:23

标签: android http flutter dart

我正在尝试开发一个flutter应用程序,以使用android studio与服务器进行通信。服务器是使用sanic python库开发的,与此类似,

from sanic import Sanic
from sanic.response import json

app = Sanic("App Name")

@app.route("/")
async def test(request):
    return json({"Name": "James"})

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=9000)

该应用程序正在使用http软件包与服务器进行通信。应用程序代码的一部分:

 void Name() {
        String cp_start_url = 'http://ipAddress:9000/';
        get(cp_start_url).then((result) {
          print(result.body);
        });
 }

我正在笔记本电脑上运行服务器脚本。在手机上测试应用程序时,我发现只有当应用程序和服务器都在同一网络上(即共享我的移动热点)时,它才能与服务器通信。通过不同网络连接时,虽然我使用服务器的正确IP地址。

代码只是示例,以避免复杂。

我无法理解我正在做的错误。

0 个答案:

没有答案