How to download a file using http.post with url encoded body in flutter?

Viewed 6370

I want to build a web app to download a pdf file in flutter using http.post method, I have already searched the internet for it but I still can't download the file. I have already tried in postman with raw json (then send and download) it works but can't do it in flutter.

Future<File> postRequest() async {
  var url = 'xxxxxxx'; <- example url

  Map dat = {
    "FileName" : "itsPdf.pdf"
  };

  File file;
  var body = json.encode(dat);

  var response = await http.post(Uri.parse(url),
      headers: {"Accept": "application/json",
          "content-type": "application/json"},
      body: body
  );

  print(response.statusCode);
  if(response.statusCode == 200) {
    file = json.decode(response.body) as File;
    return file;
  } else {
    print("ERROR");
  }
}

status code = 200

Error: FormatException: SyntaxError: Unexpected token % in JSON at position 0

0 Answers
Related