-
I am working on a Flutter application that uses Dio to connect to an API and receive a JSON text. I started working and testing on a local instance of the API and everything was well until it was time to deploy the API to a remote server. I started getting this error in from Dio on some requests:
Although these same requests work perfectly in Postman. After some digging, I found out there was a new value in the header of the requests that don't work, this new value was I tried setting What should I do to either receive the JSON correctly or decode the response bytes? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
How did you try to decode it and what happened? |
Beta Was this translation helpful? Give feedback.
-
The solution was to use a Brotli transformer to unzip (or decompress) the response data. The The code looks something like this
|
Beta Was this translation helpful? Give feedback.
The solution was to use a Brotli transformer to unzip (or decompress) the response data.
The
Content-Encoding
of the response header was set tobr
which (I didn't know) means the data was compressed using the Brotli algorithm. I then used this package that automatically transforms the data into JSON. No need to receive the data as bytes or as a stream.The code looks something like this