diff --git a/lib/codegen/dart/pkg_http.dart b/lib/codegen/dart/pkg_http.dart index 58f070b9..ff86a971 100644 --- a/lib/codegen/dart/pkg_http.dart +++ b/lib/codegen/dart/pkg_http.dart @@ -116,14 +116,13 @@ import 'dart:convert'; } var method = requestModel.method; - if (kMethodsWithBody.contains(method) && - requestModel.requestBody != null) { - var contentLength = utf8.encode(requestModel.requestBody).length; + var requestBody = requestModel.requestBody; + if (kMethodsWithBody.contains(method) && requestBody != null) { + var contentLength = utf8.encode(requestBody).length; if (contentLength > 0) { hasBody = true; - var body = requestModel.requestBody; var templateBody = jj.Template(kTemplateBody); - result += templateBody.render({"body": body}); + result += templateBody.render({"body": requestBody}); result = kBodyImportDartConvert + result; result += kBodyLength; } diff --git a/lib/providers/providers.dart b/lib/providers/providers.dart index 579a8aa4..bca9990d 100644 --- a/lib/providers/providers.dart +++ b/lib/providers/providers.dart @@ -67,7 +67,7 @@ class CollectionStateNotifier extends StateNotifier> { List? requestHeaders, List? requestParams, ContentType? requestBodyContentType, - dynamic requestBody, + String? requestBody, int? responseStatus, String? message, ResponseModel? responseModel, diff --git a/lib/services/http_service.dart b/lib/services/http_service.dart index 872ab8f9..b705ae03 100644 --- a/lib/services/http_service.dart +++ b/lib/services/http_service.dart @@ -14,15 +14,14 @@ Future<(http.Response?, Duration?, String?)> request(RequestModel requestModel) Map headers = rowsToMap(requestModel.requestHeaders) ?? {}; http.Response response; String? body; - try { - if(kMethodsWithBody.contains(requestModel.method)){ - if(requestModel.requestBody != null){ - var contentLength = utf8.encode(requestModel.requestBody).length; - if (contentLength > 0){ - body = requestModel.requestBody as String; - headers[HttpHeaders.contentLengthHeader] = contentLength.toString(); - headers[HttpHeaders.contentTypeHeader] = kContentTypeMap[requestModel.requestBodyContentType] ?? ""; - } + try { + var requestBody = requestModel.requestBody; + if(kMethodsWithBody.contains(requestModel.method) && requestBody != null){ + var contentLength = utf8.encode(requestBody).length; + if (contentLength > 0){ + body = requestBody; + headers[HttpHeaders.contentLengthHeader] = contentLength.toString(); + headers[HttpHeaders.contentTypeHeader] = kContentTypeMap[requestModel.requestBodyContentType] ?? ""; } } Stopwatch stopwatch = Stopwatch()..start();