如何正确地将查询参数添加到DART http GET请求?try 将‘?param1=one&;param2=Two’附加到我的url时,我无法获得正确响应的请求,但它在Postman中工作正常.以下是我的代码要点:
final String url = "https://www.myurl.com/api/v1/test/";
String workingStringInPostman = "https://www.myurl.com/api/v1/test/123/?param1=one¶m2=two";
Map<String, String> qParams = {
'param1': 'one',
'param2': 'two',
};
var res = await http
.get(Uri.encodeFull("$url${widget.pk}/"),
headers: {HttpHeaders.authorizationHeader: "Token $token",
HttpHeaders.contentTypeHeader: "application/json"},
);
${widget.pk}只是传递的整数值(请参见workingStringInPostman变量中的值123).
qParams是为了在需要URI参数时使用.
欢迎使用代码示例.