-
-
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
Header could not send some mystery charactor #1959
Comments
@BenderBlog I had a similar issue a couple of days ago, and ended up having to place a ReGex guard on my headers to keep it running. |
I'm not sure if we can do something to help the circumstances. Header fields will eventually parsed by the parser embedded in the Dart, there seems to be no way to bypass the routine at this moment. Could you evaluate the possibility of sending a raw request based on a |
You mean changing the dart's implementation on headers, like this? dart-lang/sdk#42902 |
We put the headers object through a ReGex filter, before adding it to the request. final cleanHeaders = oldHeaders.map((key, value) => value is String ? MapEntry(key, _removeNonAsciiChars(value)) : MapEntry(key, value)); The implementation of For instance, we register the public name of the wifi network from which the user is making the request: {
'xWifiName':'Wifi do Paço'
} The names tend to contain a lot of non-ascii chars, since the app is used by Portuguese-speaking customers. {
'xWifiName':'Wifi do Pa_231_o'
} Where 231 is the ASCII code for the At last, my opinion on this matter is: This kind of filter/treatment should not be part of dart-lang SDK or even the Dio Package. |
Based on #1959 (comment) from @DouglasValerio, you can try to submit a proposal to the Dart team, and see if they can handle this better. Closing as there is nothing Dio can do at this moment. |
OK I have some solution right here. You can encode the data with UrlEncoder, like |
Retrofit 2.10 added support for non-ascii characters on headers because is supported or even required for some services. https://github.com/square/retrofit/blob/trunk/CHANGELOG.md#2100---2024-03-18 If you need to send device model on headers for some pruporse, it's not possible to send "iPhone XR", because Apple use a small R on model name witch isn't a ASCII character and needs a special treatment just for this case. It tooks months to figure out what was happening, because this problem was affecting only iPhone XR devices. |
Package
dio
Version
5.3.2
Operating-System
iOS
Output of
flutter doctor -v
Dart Version
3.13.2
Steps to Reproduce
example code
cookie example
especially
这里再用中文解释一下我的问题:
这个服务器使用 GBK 编码,其返回的 Cookie 包含 GBK 编码的中文字符。Dart 使用 UTF-16 解码会出现不合适的字符,然后当我想用这个 Cookie POST 请求的时候,其报错会引出“非法字符错误”。
顺便,我直接用中文发过去,照样报错。
根据 Cookie 规范,其只能是 ASCII 字符,但对于老服务器,有时候不会是这样。所以请求各位能考虑一下适配这样不太合适的需求吗,让 Headers 放行这样不正常的字符。
Expected Result
Well, it sends
Actual Result
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: DioException [unknown]: null
Error: FormatException: Invalid HTTP header field value: "PhyEws_StuName=任�涵; path=/" (at character 16)
PhyEws_StuName=任�涵; path=/
^
#0 DioMixin.fetch. (package:dio/src/dio_mixin.dart:507:7)
#1 _RootZone.runUnary (dart:async/zone.dart:1661:54)
#2 _FutureListener.handleError (dart:async/future_impl.dart:174:22)
#3 Future._propagateToListeners.handleError (dart:async/future_impl.dart:852:47)
#4 Future._propagateToListeners (dart:async/future_impl.dart:873:13)
#5 Future._completeError (dart:async/future_impl.dart:649:5)
#6 _SyncCompleter._completeError (dart:async/future_impl.dart:60:12)
#7 _Completer.completeError (dart:async/future_impl.dart:26:5)
#8 Future.any.onError (dart:async/future.dart:620:45)
#9 _RootZone.runBinary (dart:async/zone.dart:1666:54)
#10 _FutureListener.handleError (dart:async/<…>
The text was updated successfully, but these errors were encountered: