2012-04-14 57 views
1

我使用URLEncoder class编码了我的字符串(Say String a =“123 + gtyt”)。编码的字符串是String b。然后我发送“String b”作为附加到URL的参数。可以说http://example.com?request=b
谁正在解码URLencoding?

当我解码字符串在example.com使用URLDecoder,在我的字符串符号+失踪,我没有收到“字符串为”解码

现在后当我打印照片,无需解码example.com上的“String b”。 我得到的字符串正好是



所以我的疑问是解码是否由浏览器本身进行重定向?

+1

你能告诉你正在使用的确切的代码? – Torious 2012-04-14 13:10:41

+0

对于编码
字符串xmlString1 = URLEncoder.encode(的xmlString, “UTF-8”); 字符串reqString = “http://example.com/saml/IDProvider"+"?SAMLRequest=” + xmlString1; – suraj 2012-04-14 13:20:28

+0

@Torious对于装饰在example.com,字符串响应= request.getParameter(“响应”);
字符串xmlString2 = URLDecoder.decode(响应,“UTF-8”) – suraj 2012-04-14 13:22:09

回答

1

当你编码 “123 + gtyt” - 它编码的加号。

当你处理HTTP请求,小服务程序API automaticaly对其进行解码以 “123 + gtyt”。如果您再次解码它,则会将“+”更改为空格。

所以关键是 - 没有明确解码参数。

例如:

final String encoded = URLEncoder.encode("123+gtyt"); 
    final String decoded = URLDecoder.decode(encoded); 
    System.out.println("decoded = " + decoded); // 123+gtyt 
    System.out.println("URLDecoder.decode(decoded) = " 
       + URLDecoder.decode(decoded)); // prints 123 gtyt 
+0

有什么办法阻止servlet API自动解码编码的字符串 – suraj 2012-04-14 13:55:22

+0

简短的回答是否定的。只是不要解码来自API的内容。 – 2012-04-14 14:29:26

+0

oki :)谢谢你:) – suraj 2012-04-14 14:46:49