Dart/Flutter:URI/HTTPClient - 禁用 % 的自动转义 [英] Dart/Flutter: URI/HTTPClient - disable automatic escaping of %

查看:56
本文介绍了Dart/Flutter:URI/HTTPClient - 禁用 % 的自动转义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 dart/flutter URI 实现有问题.% 自动替换为 %25.

I have a problem with the dart/flutter URI implementation. % is automatically replaced by %25.

我想访问以下网址:http://some.domain/json.php?key=%DF [ASCII/latin1 中的 %DF=ß]

i want to access the following URL: http://some.domain/json.php?key=%DF [%DF=ß in ASCII/latin1]

代码:

    final uri = Uri.http('some.domain', 'json.php', {'key': 'ß'});

导致http://some.domain/json.php?key=%C3%9F [UTF-8 中的ß]

results in http://some.domain/json.php?key=%C3%9F [ß in UTF-8]

尝试时

    final uri = Uri.http('some.domain', 'json.php', {'key': '%DF'});

结果:http://some.domain/json.php?key=%25DF [% 自动转义到 %25]

it results in: http://some.domain/json.php?key=%25DF [% automatically escaped to %25]

尝试显式编码时:

    final uri = Uri.http('some.domain', 'json.php',
        {'key': Uri.encodeQueryComponent('ß', encoding: latin1)});      

结果:http://some.domain/json.php?key=%25DF [% 自动转义到 %25]

it results in: http://some.domain/json.php?key=%25DF [% automatically escaped to %25]

如何禁用 % 到 %25 的自动编码?!

How can I disable the automatic encoding of % to %25?!

有什么想法吗?

推荐答案

Uri.http 构造函数的 queryParameters 参数需要一个未编码的数据映射,它使用它进行编码它是自己的标准,因为您需要在这种情况下使用另一个标准,最好使用 Uri 构造函数并构建您自己的查询字符串并传递给 query 参数.

The queryParameters parameter of the Uri.http constructor expects an unencoded map of data that it encodes using it's own standard, since you need to use another standard for this case might be better to use the Uri constructor and build your own query string and pass to the query parameter.

这样的事情应该可以解决问题:

Something like this should do the trick:

final uri = Uri(
  scheme: 'http',
  host: 'some.domain',
  path: 'json.php',
  query: 'key=${Uri.encodeQueryComponent('ß', encoding: latin1)}'
);

这篇关于Dart/Flutter:URI/HTTPClient - 禁用 % 的自动转义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆