1

I wanted to send raw data in flutter http and the data doesn't look like JSON

Here's how I done that in Postmanenter image description here

and tried this in flutter using http,

 Response res = await post(
      Uri.parse(baseUrl + endPoint),
      headers: {'Client-ID': clientId, 'Authorization': 'Bearer $accessToken'},
      body: jsonEncode('fields *'),
    );

and got this in console,

Error: XMLHttpRequest error.
2

1 Answer 1

4

Add it as this

var headers = {
  'Accept': 'application/json',
  'Content-Type': 'text/plain',
  
};
var request = http.Request('POST', Uri.parse('Your url'));
request.body = '''fields *''';
request.headers.addAll(headers);

http.StreamedResponse response = await request.send();

if (response.statusCode == 200) {
  print(await response.stream.bytesToString());
}
else {
  print(response.reasonPhrase);
}

Or you can easily see it being implemented in Postman's code request to the right just select the code icon and choose http-Dart

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.