Java URL 编码:使用 URLEncoder 类
Java 提供了一个 URLEncoder 类来进行 URL 编码。可以使用它的静态方法 encode() 来对字符串进行编码。例如:
String str = 'Hello World!';
String encodedStr = URLEncoder.encode(str, 'UTF-8');
System.out.println(encodedStr);
输出结果为:
Hello+World%21
其中,'UTF-8' 是编码字符集,可以根据需要进行修改。
原文地址: https://www.cveoy.top/t/topic/jTWq 著作权归作者所有。请勿转载和采集!