'Invalid characters while converting API response to PDF

I used the following syntax for my GET request

var response = await http.get(Uri.parse(url), headers: {
    "Content-Type": "application/pdf",
    'Authorization': 'Bearer $token',
    'Accept': 'application/pdf',
}

I am expecting a PDF in response ,but this is what I got -

 %PDF-1.7
 
  1 0 obj
  <<
    /Type /Catalog
    /Pages 2 0 R
  >>
  endobj
 
  2 0 obj
  <<
    /Type /Pages
    /MediaBox [ 0 0 595.00 842.00 ]
    /Count 1
    /Kids [  5 0 R  ]
  >>
  endobj

I tried converting the response of API by decoding it using BASE64 as follows -

base64.decode(response.body)

But got invalid characters as output.What should I do?

I tried response.bodyBytes it returned me some byte array, now how should Ii convert it to PDF/Image?

An update : This is an official issue page of that API , and people are getting back a blob format. Am I using the API in a wrong way?



Solution 1:[1]

You need a response in byteCode or you can say in Unit8List,

So if you use http for API calls then whatever response you get returns it In bytecode like the below code.

response.bodyBytes.

or if you using Dio then you can use the below code.

await dio.post(finalUrl,
      options: Options(
          responseType: ResponseType.bytes,
          headers: headers,),
      data: encodedBody,);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BC TUBE