如何不要转义(编码)URL中的特殊字符

turbogears 2015-09-25 07:54:57
按规范,URL中的特殊字符需要被转义,包括(^)。QUrl忠实执行,所有的特殊字符都被强制转义(编码)了。
但是问题来了。
有个网站,其URL中包含有^,用IE等浏览器可正常访问,没被转义(编码)。用QWebKit就不行了,^被转义(编码)成了%5E,无法访问这个链接了。
怎么办?
有没有办法要求QUrl不要转义(编码)^这个字符?

space / double-quote / "<" / ">" / "" / "^" / "`" / "{" / "|" / "}"


Constant Value Description
QUrl::TolerantMode 0 QUrl will try to correct some common errors in URLs. This mode is useful for parsing URLs coming from sources not known to be strictly standards-conforming.
QUrl::StrictMode 1 Only valid URLs are accepted. This mode is useful for general URL validation.
QUrl::DecodedMode 2 QUrl will interpret the URL component in the fully-decoded form, where percent characters stand for themselves, not as the beginning of a percent-encoded sequence. This mode is only valid for the setters setting components of a URL; it is not permitted in the QUrl constructor, in fromEncoded() or in setUrl(). For more information on this mode, see the documentation for QUrl::FullyDecoded.
...全文
5104 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
huodao0204 2017-09-12
  • 打赏
  • 举报
回复
url.setScheme("https"); url.setHost("127.0.0.1"); 可破
小志志志 2017-06-25
  • 打赏
  • 举报
回复
这个问题楼主解决了吗》同问
turbogears 2015-10-28
  • 打赏
  • 举报
回复
真的是无解?
turbogears 2015-10-06
  • 打赏
  • 举报
回复
我的提问有问题,应该这样问。 由字符串生成QUrl时如何不要对其中的特殊字符进行编码? 形如:http://example.com/?aa^bbb的字符串,其中含有特殊字符 ^ 在生成QUrl时,如何控制才能不要对 ^ 进行编码? 即生成QUrl("http://example.com/?aa^bbb")而不是QUrl("http://example.com/?aa%E5bbb")。 不要将 ^ 编码成 %E5
bajie168 2015-09-30
  • 打赏
  • 举报
回复
这和WebKit好像没有关系,看QUrl的QUrl::setEncoded***相关函数: 如:setEncodedPath
turbogears 2015-09-28
  • 打赏
  • 举报
回复
估计是没有解决办法了。 WebKit又不再更新了。 唉。

16,202

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧