1

我有网址:https://example.com/hello?param=first:last。我希望它应该被百分比编码为https://example.com/hello?param=first%3Alast. 但 Qt 保持原样。我的代码:

QUrl url("https://example.com/hello?param=first:last");
printf("Encoded: %s\n", url.toEncoded().constData());

我应该如何编码冒号?手动格式化参数QString::toPercentEncoding

4

4 回答 4

2

由于安全问题,您必须替换冒号。

更多信息: http: //www.blooberry.com/indexdot/html/topics/urlencoding.htm

您可以对冒号使用百分比编码 (":" -> "%3A"),请参阅http://qt-project.org/doc/qt-5.0/qtcore/qurl.html#fromPercentEncodinghttp://qt- project.org/doc/qt-5.0/qtcore/qurl.html#toPercentEncoding

于 2013-06-17T19:27:33.117 回答
0

已经有一些关于 URL 中冒号安全性的讨论。听起来它归结为我不精通的 RFC 遵守。

冒号对于友好 URL 使用安全吗?

看起来您可能必须自己替换任何“:”字符(在 https : 之后)。

于 2013-06-17T18:18:52.293 回答
0

我认为 QUrl::toPercentEncoding() 是你最好的选择。它默认编码所有标准字符,您可以手动指定自己的附加字符列表进行编码:

参考网址:
http ://doc.qt.digia.com/4.7/qurl.html#toPercentEncoding

于 2013-06-17T19:37:32.327 回答
-1

很确定你想要QUrl::setEncodedURL并且QUrl::toEncoded

http://harmattan-dev.nokia.com/docs/platform-api-reference/xml/daily-docs/libqt4/qurl.html

您使用的是哪个版本的 Qt?

使用 IIRC Qt 3QUrl:encode

于 2013-06-17T18:05:39.303 回答