Request Body to String? from dynamic

This commit is contained in:
Ankit Mahato
2023-03-23 03:45:11 +05:30
parent e7eee508c6
commit 454ebd4b8a
3 changed files with 13 additions and 15 deletions

View File

@ -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;
}

View File

@ -67,7 +67,7 @@ class CollectionStateNotifier extends StateNotifier<List<RequestModel>> {
List<KVRow>? requestHeaders,
List<KVRow>? requestParams,
ContentType? requestBodyContentType,
dynamic requestBody,
String? requestBody,
int? responseStatus,
String? message,
ResponseModel? responseModel,

View File

@ -14,15 +14,14 @@ Future<(http.Response?, Duration?, String?)> request(RequestModel requestModel)
Map<String, String> 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();