URLEncoder麻烦

时间:2014-01-31 17:03:28

标签: java url encoding

我有字符串Ruby On Rails,应该转换为Ruby%20On%20Rails,但URLEncoderRuby+On+Rails。这是我的尝试:

String encoded = URLEncoder.encode("Ruby On Rails");
System.out.println(encoded);

是否因为encode()方法已被弃用而发生?

1 个答案:

答案 0 :(得分:2)

URLEncoder不进行URI编码,而application/x-www-form-urlencoded则将空格转换为+符号。如果您希望将它们转换为%20,则需要使用URI编码的内容,例如Spring's UriUtils

相关问题