toHttpRequest method
Request
toHttpRequest()
Converts this request data to an HTTP request.
Implementation
Request toHttpRequest() {
var reqUrl = buildUrlString(baseUrl, params);
Request request = new Request(methodToString(method), reqUrl.toUri());
request.headers.addAll(headers);
if (encoding != null) request.encoding = encoding!;
if (body != null) {
if (body is String) {
request.body = body as String;
} 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;
}