http.get()不会在标头中添加我的参数

问题描述 投票:0回答:1

我正在尝试使用flutter访问API,我一直遇到问题。我添加了一张地图到http.get(headers: myParameters),服务器仍然没有处理我的请求,所以我打印我的.headers和我添加的地图不是标题的一部分

    var params = {"key": "apiKey"};
    Uri uri = Uri.parse("https://api.testapp.com/v1");
    var response = await http.get(uri, headers: params); 
    print(response.headers);

打印完之后,我得到了一张json地图,但是我的参数没有列出来,是否在发送请求时没有添加?

{via: 1.1 vegur, content-type: application/json, connection: keep-alive, date: Fri, 05 Apr 2019 10:14:49 GMT, content-length: 92, server: gunicorn/19.9.0}
dart flutter http-get url-parameters
1个回答
2
投票

你需要使用HttpHeaders

var params = {HttpHeaders.authorizationHeader: "Basic your_api_token_here"};
Uri uri = Uri.parse("https://api.testapp.com/v1");
var response = await http.get(uri, headers: params); 
print(response.headers);
© www.soinside.com 2019 - 2024. All rights reserved.