【发布时间】:2019-12-13 11:55:02
【问题描述】:
我想在 dart 中使用 http GET 请求发送参数。这里的第一个答案很好地证明了这一点:How do you add query parameters to a Dart http request?
var uri =
Uri.https('www.myurl.com', '/api/query', queryParameters);
但是,一个主要问题是 queryParameters 只接受:
Map<String, String>
这不允许我传入列表/数组。
如果我将获取请求更改为发布请求,我可以轻松发送 颤振文档中概述的主体(作为 json 编码的字符串):https://pub.dev/documentation/http/latest/http/post.html
post(url, {Map<String, String> headers, body, Encoding encoding})
但是,get 请求没有这样的查询参数等效参数:https://pub.dev/documentation/http/latest/http/get.html
get(url, {Map<String, String> headers})
我也尝试将查询参数直接添加到 url,如下所示:
get('www.myurl.com/api/query/?array[]=value1&array[]=value2&array[]=value3)
但是当我在服务器中收到方括号 [] 时,它总是会转换为 %5B%5D。
感谢任何帮助。 谢谢
【问题讨论】: