-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Prevent encoding query parameters #1445
Comments
Currently using the below workaround. class EncodingInterceptor extends Interceptor {
@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
if (options.queryParameters.isEmpty) {
super.onRequest(options, handler);
return;
}
final queryParams = _getQueryParams(options.queryParameters);
handler.next(
options.copyWith(
path: _getNormalizedUrl(options.path, queryParams),
queryParameters: Map.from({}),
),
);
}
String _getNormalizedUrl(String baseUrl, String queryParams) {
if (baseUrl.contains("?")) {
return baseUrl + "&$queryParams";
} else {
return baseUrl + "?$queryParams";
}
}
String _getQueryParams(Map<String, dynamic> map) {
String result = "";
map.forEach((key, value) {
result += "$key=${Uri.encodeComponent(value)}&";
});
return result;
}
} https://github.com/flutterchina/dio/blob/develop/dio/lib/src/transformer.dart#L45 |
Thanks, it works with me |
I suggest you this change to avoid errors on the qp's types sent:
|
Hi everyone. According to Try to replace: To this: // Normalize the url.
return Uri.parse(url)
.replace(queryParameters: queryParameters)
.normalizePath(); This will drop the usage of the |
This is completed because... there's a way to avoid encoding query parameters without the above workaround? The above workaround doesn't work for me. The parameters still gets encoded. Aka I want to send a query param like so:
But even if I explicitly overwrite the above without encoding I still get
Which is pretty annoying. I have no other interceptors implemented / connected. |
New Issue Checklist
Issue Description and Steps
https://github.com/flutterchina/dio/blob/develop/dio/lib/src/options.dart#L545
The above code always does the encoding of query parameters by using
+
instead of spaces. The issue is, some servers do not understand the+
, instead they use%20
.Tried to manually encode the query paramater value but then it ends up to duplicated encoding.
The text was updated successfully, but these errors were encountered: