编码和解码rfc2396 URL [英] Encode and Decode rfc2396 URLs

查看:735
本文介绍了编码和解码rfc2396 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对URL字符串进行编码的最佳方法是什么,使它们符合rfc2396并解码符合rfc2396的字符串,例如将%20替换为空格字符?

What is the best way to encode URL strings such that they are rfc2396 compliant and to decode a rfc2396 compliant string such that for example %20 is replaced with a space character?

编辑:
URLEncoder和URLDecoder类执行编码/解码符合rfc2396的URL,它们编码为MIME类型application / x-www-form-urlencoded,用于编码HTML表单参数数据。

edit: URLEncoder and URLDecoder classes do not encode/decode rfc2396 compliant URLs, they encode to a MIME type of application/x-www-form-urlencoded which is used to encode HTML form parameter data.

推荐答案

使用URI类如下:

URI uri = new URI("http", "//www.someurl.com/has spaces in url", null);
URL url = uri.toURL();

或者如果你想要一个字符串:

or if you want a String:

String urlString = uri.toASCIIString();

这篇关于编码和解码rfc2396 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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