Created
January 28, 2021 04:38
-
-
Save dhruvilp/83e559229324326729d65171473bcd0b to your computer and use it in GitHub Desktop.
Compressing POST requests in flutter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void sendCompressed() async { | |
| var gzip = GZipCodec(); | |
| String jsonToSend = '{"field1":"Some JSON to send to the server."}'; | |
| var compressedBody = gzip.encode(jsonToSend.codeUnits); | |
| Map<String, String> headers = { | |
| "Content-Encoding": "gzip", | |
| "Content-Type": "application/json; charset=UTF-8", | |
| }; | |
| var response = await http.post( | |
| "https://example.com/api/v1", | |
| headers, | |
| compressedBody ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment