Home > Net >  Dart server side: How to receive data from the Postman (form-data)?
Dart server side: How to receive data from the Postman (form-data)?

Time:10-31

Example data from the Postman:enter image description here

I will get this error after I send a request.

Unhandled exception:
FormatException: Unexpected extension byte (at offset 435)

If I don't send image 1, I got this.

jsonString:
----------------------------166099235909119466948633
Content-Disposition: form-data; name="key 1"
Content-Type: application/json

value 1
----------------------------166099235909119466948633
Content-Disposition: form-data; name="key 2"

value 2
----------------------------166099235909119466948633--

This can't use JSON decode.

My code:

Future main(List<String> arguments) async {
  HttpServer server = await HttpServer.bind('localhost', 8085);
  server.listen((HttpRequest request) async {
    String jsonString = await request.cast<List<int>>().transform(utf8.decoder).join();
    print("jsonString:\n$jsonString");
    await request.response.close();
  });
}

CodePudding user response:

I follow enter image description here

This solution work with http.MultipartRequest() from the Flutter app.

  • Related