无法将参数类型“String"分配给参数类型“Uri"

无法将参数类型“String

问题描述:

我正在尝试使用 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 引入了重大更改,使以前接受 Uris 或 Strings 的所有函数现在接受 only Uri 代替.您将需要明确使用 Uri.parseStrings 创建 Uris.(package:http 以前在内部为您调用.)

To improve compile-time type safety, package:http 0.13.0 introduced breaking changes that made all functions that previously accepted Uris or Strings now accept only Uris instead. You will need to explicitly use Uri.parse to create Uris from Strings. (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",
  });