无法将参数类型“String"分配给参数类型“Uri"
我正在尝试使用 flutter 插件 HTTP 发出 HTTP POST 请求,但出现标题错误.有没有人知道这是什么原因,因为在我的其他应用程序中这工作得很好?
I am trying to make an HTTP POST request with the flutter plugin HTTP but I am getting an error of the title. Does anyone know the cause of this since in my other applications this works just perfectly fine?
await http.post(Uri.encodeFull("https://api.instagram.com/oauth/access_token"), body: {
"client_id": clientID,
"redirect_uri": redirectUri,
"client_secret": appSecret,
"code": authorizationCode,
"grant_type": "authorization_code"
});
为了提高编译时类型安全性,package:http
0.13.0 引入了重大更改,使以前接受 Uri
s 或 String
s 的所有函数现在接受 only Uri
代替.您将需要明确使用 Uri.parse
从 String
s 创建 Uri
s.(package:http
以前在内部为您调用.)
To improve compile-time type safety, package:http
0.13.0 introduced breaking changes that made all functions that previously accepted Uri
s or String
s now accept only Uri
s instead. You will need to explicitly use Uri.parse
to create Uri
s from String
s. (package:http
formerly called that internally for you.)
旧代码 | 替换为 |
---|---|
http.get(someString) |
http.get(Uri.parse(someString)) |
http.post(someString) |
http.post(Uri.parse(someString)) |
(等等.)
在您的具体示例中,您需要使用:
In your specific example, you will need to use:
await http.post(
Uri.parse("https://api.instagram.com/oauth/access_token"),
body: {
"client_id": clientID,
"redirect_uri": redirectUri,
"client_secret": appSecret,
"code": authorizationCode,
"grant_type": "authorization_code",
});