无法将参数类型“String"分配给参数类型“Uri" [英] The argument type 'String' can't be assigned to the parameter type 'Uri'

查看:35
本文介绍了无法将参数类型“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 引入了重大更改,使以前接受 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",
  });

这篇关于无法将参数类型“String"分配给参数类型“Uri"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆