Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

body: <FormatException: Missing extension byte (at offset 2)> #1235

Open
carlospo opened this issue Jun 14, 2024 · 1 comment
Open

body: <FormatException: Missing extension byte (at offset 2)> #1235

carlospo opened this issue Jun 14, 2024 · 1 comment
Labels
package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@carlospo
Copy link

sdk: '>=3.4.0 <4.0.0'
http: ^1.2.1

I encountered an issue with an HTTP request in version 1.2.1. Here is the original function I used:
Future getRequest(String url) async {
var headers = {
'Authorization': 'Bearer $token',
'Accept': '/',
'Accept-Encoding': 'gzip, deflate, br',
'Connection': 'keep-alive'
};
final apiUrl = Uri.parse(base_url + url);
// return await get(apiUrl, headers: headers);
final response = await retry(
// Make a GET request
() => get(apiUrl, headers: headers).timeout(const Duration(seconds: 15)),
// Retry on SocketException or TimeoutException
retryIf: (e) => e is SocketException || e is TimeoutException,
);
return response;
}
To resolve the issue, I made the following change:
Future getRequest(String url) async {
var headers = {
'Authorization': 'Bearer $token',
'Accept': '/',
// 'Accept-Encoding': 'gzip, deflate, br',
'Connection': 'keep-alive'
};
final apiUrl = Uri.parse(base_url + url);
// return await get(apiUrl, headers: headers);
final response = await retry(
// Make a GET request
() => get(apiUrl, headers: headers).timeout(const Duration(seconds: 15)),
// Retry on SocketException or TimeoutException
retryIf: (e) => e is SocketException || e is TimeoutException,
);
return response;
}
By simply removing 'Accept-Encoding': 'gzip, deflate, br' from the headers, the body of the response was understood correctly again.
http_issue

@carlospo carlospo added package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jun 14, 2024
@LandChanning
Copy link

i have same error

http: ^1.2.1

url:https://m.gaonaojin.com

header: 'Accept-Encoding': 'gzip, deflate, br'

error:FormatException: Unexpected extension byte (at offset 5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants