如何在Java中进行urlencode、rawurlencode、urldecode、rawurldecode?

发布于 2024-12-05 08:39:43 字数 574 浏览 10 评论 0 原文

如何在 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); //!!

How do you do RAW/URL encode/decode in JAVA?

Got something which asked URLencoded or RAWURLencoded need to be sent. After looking here and there, did not find any url/rawurl encoder/decoder available. How do you make it?

Example:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

傾旎 2024-12-12 08:39:43

对于 urlencode/urldecode (application/x-www-form-urlencoded 变体),您可以使用 URLEncoder
URLDecoder< /a>.

对于“原始”版本,您可以使用 URI 类,它自动执行此任务。

For urlencode/urldecode (the application/x-www-form-urlencoded variants), you can use URLEncoder
and URLDecoder.

For the "raw" versions, you can use the URI class, which performs this task automatically.

柳絮泡泡 2024-12-12 08:39:43

如果您想要“%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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文