getRequest method

Future<HttpClientRequest> getRequest(
  1. String method,
  2. String action, {
  3. Map<String, String?> params = const {},
  4. Map<String, String?> headers = const {},
  5. String? token,
})
inherited

Implementation

Future<HttpClientRequest> getRequest(String method, String action,
    {Map<String, String?> params = const {},
    Map<String, String?> headers = const {},
    String? token}) async {
  String urlParams =
      params.keys.toList().map((e) => e + "=" + (params[e] ?? "")).join("&");
  if (urlParams.isNotEmpty) {
    urlParams = "?" + urlParams;
  }
  HttpClient client = HttpClient();

  if (!action.startsWith("/")) {
    action = "/" + action;
  }

  var req = await client.openUrl(
      method, Uri.parse("${_config.uri}$action$urlParams"));

  headers.forEach((key, value) {
    req.headers.add(key, value ?? "");
  });
  Map<String, String> _headers = {};
  req.headers.forEach((name, values) {
    _headers[name] = values[0];
  });
  var sighn = getSign(method, action, params: params, headers: _headers);
  req.headers.add("Authorization", sighn);
  if(token != null){
    req.headers.add("x-cos-security-token", token);
  }
  return req;
}