如何在Java中进行urlencode、rawurlencode、urldecode、rawurldecode?
如何在 JAVA 中进行 RAW/URL 编码/解码?
收到一些要求发送 URL 编码或 RAWURL 编码的内容。到处查看后,没有找到任何可用的 url/rawurl 编码器/解码器。你怎么做到的?
例子:
String webBrowser = "how=WebRSS&what=Tandory chicken is nice with rice, lets cook for my honey";
String encoded = null;
/**
* Output: how%3DWebRSS%26what%3DTandory+chicken+is+nice+with+rice%2C+lets+cook+for+my+honey
*/
urlencode(webBrowser);
/**
* Output: how%3DWebRSS%26what%3DTandory%20chicken%20is%20nice%20with%20rice%2C%20lets%20cook%20for%20my%20honey
*/
rawurlencode(webBrowser);
postIt(encoded); //!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于
urlencode
/urldecode
(application/x-www-form-urlencoded 变体),您可以使用URLEncoder
和URLDecoder
< /a>.对于“原始”版本,您可以使用
URI
类,它自动执行此任务。For
urlencode
/urldecode
(the application/x-www-form-urlencoded variants), you can useURLEncoder
andURLDecoder
.For the "raw" versions, you can use the
URI
class, which performs this task automatically.如果您想要“%20”(例如),那么您需要使用 java.net.URI。它实现了 RFC 2396。
If you want "%20" (for example), then you you want to use java.net.URI. Which implements RFC 2396.