http.get() 没有在 headers 中添加我的参数
http.get() does not add my parameters in headers
我正在尝试使用 flutter 访问 API,但我一直遇到问题。我向 http.get(headers: myParameters)
添加了一张地图,但服务器仍未处理我的请求,因此我打印了我的 .headers
并且我添加的地图不属于 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);
我正在尝试使用 flutter 访问 API,但我一直遇到问题。我向 http.get(headers: myParameters)
添加了一张地图,但服务器仍未处理我的请求,因此我打印了我的 .headers
并且我添加的地图不属于 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);