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

查看:59
本文介绍了无法将参数类型“字符串"分配给参数类型"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的所有函数现在接受 Uri .

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.

您将需要使用 Uri.parse String 转换为 Uri :

You will need to use Uri.parse to convert a String into a Uri:

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",
  });

通常,如果您以前使用过 http.get(someString) http.post(someString)等,则需要使用 http.get(Uri.parse(someString)) http.post(Uri.parse(someString))等.( package:http 以前是内部为您使用的 Uri.parse .)

More generally, if you previously used http.get(someString), http.post(someString), etc. you instead will need to use http.get(Uri.parse(someString)), http.post(Uri.parse(someString)), and so on. (package:http formerly called Uri.parse internally for you.)

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

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