在 Flutter 中获取请求:- 'String' 不能分配给参数类型 'Uri'

问题描述

我已将 http 版本添加到 pubspec.yaml 文件中的 ^0.13.0,我只需要从 Public-apis.io 获取 Yes NO API 请求即可生成一些 Yes/No GIF,同时使用 Get 请求它说,

不能将参数类型“String”分配给参数类型“Uri”。

对此有什么解决方案吗?enter image description here

解决方法

你应该使用:

http.get(Uri.parse("https://yesno.wtf/api"))
,

它有效:

Response response = await get(Uri.https("owlbot.info","/api/v4/dictionary/"));

或者,使用令牌和参数:

 Response response = await get(Uri.https("owlbot.info","/api/v4/dictionary/"+ _controller.text.trim()),headers: {"Authorization": "Token " + _token});

更多信息: https://pub.dev/packages/http/example

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...