i'm using URLCodec
from Apache Commons Codec to encode URL, but it encode space as +
NOT as %20
why? and what is the solution?
i'm using URLCodec
from Apache Commons Codec to encode URL, but it encode space as +
NOT as %20
why? and what is the solution?
Of course, you can always do url.replace("+", "%20");
if you need it (after encoding)
String#replace
function (w3schools.com/jsref/jsref_replace.asp), you wouldn't know that you can supply a function for the second parameter, which is really useful. –
Butz url.replace(" ", "%20");"
... That would be a bad idea (you don't want to do this before encoding, you'll end up with an encoded %
; and the space isn't there after encoding). You'd want .encode(str).replace("+", "%20");
. –
Butz Because +
is an equally valid way of encoding a space. What are you trying to "solve"?
The URLCodec encodes stuff suitable a submitted form, which is not the same as percent encoding a URL. There's more explanation in this question
See this question for how you should encode your URL.
© 2022 - 2024 — McMap. All rights reserved.