toHttpRequest method

Request toHttpRequest()

Implementation

Request toHttpRequest() {
  var reqUrl = Uri.parse(addParametersToStringUrl(baseUrl, params));

  Request request = new Request(methodToString(method), reqUrl);

  request.headers.addAll(headers);
  if (encoding != null) request.encoding = encoding!;
  if (body != null) {
    if (body is String) {
      request.body = body;
    } else if (body is List) {
      request.bodyBytes = body?.cast<int>();
    } else if (body is Map) {
      request.bodyFields = body.cast<String, String>();
    } else {
      throw new ArgumentError('Invalid request body "$body".');
    }
  }

  return request;
}