2

I was trying to create a simple dart server, glad it's working, but...

   Future<Response> _echoHandler(Request request) async{
    final message = await request.readAsString();
    print(message);
    return Response.ok('$message\n');
  }

this is how that message looks like

----------------------------116375419757550841191749
Content-Disposition: form-data; name="message"

asdf
----------------------------116375419757550841191749--

Postman testingenter image description here

I want to extract this message.

MANISH
  • 2,883
  • 4
  • 11
  • 30
Shanu
  • 311
  • 2
  • 16
  • Couldn't encode parameters in json from Postman, So I tried running client also in dart using http package, and it worked – Shanu Sep 20 '22 at 07:19

3 Answers3

0

you have to encode your data in the Json format then you can retrieve your data from the response

  • I'm sending data from postman as FarmData. I believe that will be send as JSON. But the data I'm getting inside the server is not in JSON format. – Shanu Sep 15 '22 at 06:35
  • ask your backend developer to send the data in JSON format and then you can decode it using JSON encoder – Udit Shrimali Sep 20 '22 at 05:03
0

For me. I change form-data to raw. Then I can get data by using:

String jsonString = await request.cast<List<int>>().transform(utf8.decoder).join();
var data = json.decode(jsonString);

However, I want to use form-data too. I am converting another language server API to dart language. So, this must test in the same solution.

0

After I read this. I found shelf_multipart package can get data and files from the request with form-data.

You can follow my code.