【问题标题】:Dart - how to send query parameter array with bracketsDart - 如何发送带括号的查询参数数组
【发布时间】:2021-12-06 13:35:52
【问题描述】:

使用 Flutter/Dart - 我想使用包含数组的 queryParameters 进行 Uri 网络调用。

例如:

Map<String, dynamic> queryParameters = {
        'include': 'messages',
        'scopes': ['withHasUnreadMessages', 'withSubscriberUserIds'],
};
uri = Uri.https(_getBaseUrl(), '/mypath', queryParameters);

哪些打印:

https://mypath?include=subscribers&amp;scopes=withHasUnreadMessages&amp;scopes=withSubscriberUserIds

但是,我的 api 服务器 (PHP) 不能很好地处理包含重复键的请求。我的服务器想要:

https://mypath?include=subscribers&amp;scopes[]=withHasUnreadMessages&amp;scopes[]=withSubscriberUserIds

有没有办法在飞镖 Uri 查询参数中添加括号?

PS - 这可能是评论https://stackoverflow.com/a/57367680/6010500,但我没有声誉积分。

【问题讨论】:

  • 'scopes[]': ['withHasUnreadMessages', 'withSubscriberUserIds'],会不会不行
  • @n69s 这太完美了——不知道为什么我没有想到这一点。是的,它有效!
  • @N69S - 为什么不添加这个作为答案?
  • 从未使用过飞镖或对正确的语法有任何想法:)

标签: dart uri


【解决方案1】:

不是飞镖用户,但乍一看,你可以在输入名称中添加数组括号

Map<String, dynamic> queryParameters = {
        'include': 'messages',
        'scopes[]': ['withHasUnreadMessages', 'withSubscriberUserIds'],
};
uri = Uri.https(_getBaseUrl(), '/mypath', queryParameters);

【讨论】:

  • 完美,不知道为什么我没想到。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-01-03
  • 1970-01-01
  • 1970-01-01
  • 2023-03-20
  • 1970-01-01
  • 2014-10-20
  • 2021-07-28
相关资源
最近更新 更多