我正在尝试使用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}
答案 0 :(得分: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);