首页 > 解决方案 > 从flutter模拟器发送http请求到localhost api/win10

问题描述

我的 PC 和颤振模拟器上有 API。当我通过提琴手发布 Json 测试我的 API 时 -http://localhost:51797/test它工作正常。

当我尝试通过颤振调用我的 API 时, var url = Uri.parse('http://localhost:51797/test'); 我收到此消息

I/flutter (29903): http://localhost:51797/test E/flutter (29903): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] 未处理异常:SocketException:操作系统错误:连接被拒绝, errno = 111,地址 = 本地主机,端口 = 52824

然后我读到我必须使用var url = Uri.parse('http://10.0.2.2:51797/test'); ,当我这样做时,我得到

http://10.0.2.2:51797/test E/flutter (29903): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] 未处理异常:FormatException:意外字符(在字符 1) E/flutter( 29903): <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"""http://www.w3.org/TR/html...

在这里还能做些什么来解决这个问题?

标签: flutterapihttplocalhost

解决方案


推荐阅读