flutter - Flutter http.get('url') 参数出现错误它不接受 URL 字符串
问题描述
我正在尝试获取https://www.thecocktaildb.com/api/json/v1/1/filter.php?c=Cocktail api 返回的所有 json 数据,以在我的颤振应用程序中使用它
var api="https://www.thecocktaildb.com/api/json/v1/1/filter.php?c=Cocktail";
var res=await http.get(api);
drinks= jsonDecode(res.body)["drinks"];
但是它在 http.get(api) 函数调用中的 api 参数下给出了红色下划线,即“字符串类型的参数不能转换为 URI”如何解决这个问题?我什至尝试使用
res=await http.get(Uri.https('www.thecocktaildb.com','/api/json/v1/1/filter.php?c=Cocktail'));
但出现错误“连接到服务协议时出错:无法连接到http://127.0.0.1:63573”/_fprblq_tiY=/”
解决方案
而不是使用Uri.https()
,尝试使用Uri.parse()
推荐阅读
- django - 外键无法识别
- javascript - 无法在 javascript 和 html 中显示日期类型的插入字段
- javascript - 在 Foreach 中显示和隐藏
- c - pthread_cancel 后的分段错误
- wordpress - 这是否可以使用 WordPress 获得 3 级子菜单/项目?
- python-3.x - 使用 Jupyter Notebook 或终端在 matplotlib 中显示表情符号
- matlab - 弹丸运动
- facebook-javascript-sdk - 我如何忘记最后一个使用 facebook js sdk 的用户
- java - 在 Java 8 中将控制器添加到 fxml 文件时出现 LoadException
- matlab - 在matlab中创建一个返回字符串数组的函数时出错?