我正在尝试使用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}
你需要使用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);