Home > Blockchain >  HTTP POST with raw body - Flutter/Dart
HTTP POST with raw body - Flutter/Dart

Time:08-06

I am getting this error

flutter: response body:{"Message":"The request entity's media type 'text/plain' is not supported for this resource."}

which i am getting in post whenever i am changing the body type to text instead of json. How can i solve this. here are the postman screenshots of both successful request and field request are given below

enter image description here enter image description here

Here is the post method

Future<String> sendRequest() async {
  var jsonArray = json.encode(body);
  algo.Encrypted encrypted = Algorithm.encrypt(algorithmKey, jsonArray);
  var encryptedBosy = jsonEncode({'body': encrypted.base64});
  var response = await https.post(
    Uri.parse("$baseUrl/$paymentMethod"),
    headers: {
      "Key": key,
      "secretKey": secretKey,
    },
    body: encryptedBosy,
  );
  return response.body;
}

CodePudding user response:

Add the content type header to the request.

headers: <String, String>{
  'Content-Type': 'application/json; charset=UTF-8',
},
  • Related