You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's an assumption when doing a request and pass body into..
...
if (body != null) {
String contentTypeHeader;
if (body is String) {
bodyString = body;
contentTypeHeader = "text/plain";
} else if (body is Map || body is List) {
bodyString = Common.toJson(body);
if (bodyEncoding == RequestBodyEncoding.JSON) {
contentTypeHeader = "application/json";
} else if (bodyEncoding == RequestBodyEncoding.FormURLEncoded) {
contentTypeHeader = "application/x-www-form-urlencoded";
} else {
throw Exception('unsupported bodyEncoding "$bodyEncoding"');
}
}
if (contentTypeHeader != null && !Common.hasKeyIgnoreCase(headers, "content-type")) {
headers["content-type"] = contentTypeHeader;
}
}
...
When the body is Map or List, always convert to json... but in some scenarios this is wrong, for instance, in a request like this:
POST /api/login HTTP/1.1
Host: foo.com
Content-Type: application/x-www-form-urlencoded
Accept: */*
username=someusername&password=somepassword
Data needs to pass like key/value map, so only convert to json when you establish content type to "application/json", in any other case just pass raw body to the request.
The text was updated successfully, but these errors were encountered:
There's an assumption when doing a request and pass body into..
When the body is Map or List, always convert to json... but in some scenarios this is wrong, for instance, in a request like this:
Data needs to pass like key/value map, so only convert to json when you establish content type to "application/json", in any other case just pass raw body to the request.
The text was updated successfully, but these errors were encountered: