Character + is converted to %2B in HTTP Post

102.8k views Asked by At

I'm adding functionality to a GM script we use here at work, but when trying to post (cross site may I add) to another page, my posting value of CMD is different than what it is on the page.

It's supposed to be Access+My+Account+Info but the value that is posted becomes Access%2BMy%2BAccount%2BInfo.

So I guess my question is: What's escaping my value and how do I make it not escape? And if there's no way to unescape it, does anyone have any ideas of a workaround?

Thanks!

My Issue

3

There are 3 answers

3
James M On BEST ANSWER

%2B is the code for a +. You (or whatever framework you're using) should already be decoding the POST data server-side...

0
Roland J. On

Just a quick remark: If you want to decode a path segment, you can use UriUtils (spring framework):

@Test
public void decodeUriPathSegment() {
   String pathSegment = "some_text%2B"; // encoded path segment
   String decodedText = UriUtils.decode(pathSegment, "UTF-8");
   System.out.println(decodedText);
   assertEquals("some_text+", decodedText);
}

Uri path segments are different from HTML escape chars (see list). Here is an example:

@Test
public void decodeHTMLEscape() {
    String someString = "some_text+";
    String stringJsoup = org.jsoup.parser.Parser.unescapeEntities(someString, false);
    String stringApacheCommons = StringEscapeUtils.unescapeHtml4(someString);
    String stringSpring = htmlUnescape(someString);

    assertEquals("some_text+", stringJsoup);
    assertEquals("some_text+", stringApacheCommons);
    assertEquals("some_text+", stringSpring);
}
0
Nataraj D On

/data/v50.0/query?q=SELECT Id from Case

This worked for me. Give space instead of '+'