Is java URLEncoder.encode the same as PHP urlencode?

are java URLEncoder.encode and PHP urlencode the same?

how not? so it has the same effect as that PHP function. Thank you

.
Mar.25,2021

the same, they are all encoded for url


there is actually a difference. Php's urlencode will change the asterisk * to% 2A, while java's will keep it. In the past, I stepped on this hole when interfacing with the interface, because the urlencode result was inconsistent, which led to the failure of visa verification

.

the following is the result of php and java's treatment of the nine unreserved symbols specified by RFC2396 . You can see that there is a difference in the treatment of * and ~
php
java

RFC2396

Data characters that are allowed in a URI but do not have a reserved
purpose are called unreserved. These include upper and lower case
letters, decimal digits, and a limited set of punctuation marks and
symbols.


Unreserved characters can be escaped without changing the semantics
of the URI, but this should not be done unless the URI is being used
in a context that does not allow the unescaped character to appear.


PHPrawurlencodeurlencode, urlencode
php urlencode

.

it can be seen that the difference between urlencode and URLEncoder in handling unreserved characters is only reflected in the symbol " * ".
it is worth noting that Baidu search for "the difference between urlencode and rawurlencode". The blog posts found basically only mentioned the difference in the treatment of " + ", but did not mention " ~ "

.

the running result of the above code is based on an online tool, and the possibility of inconsistent results running in different environments (language versions) is not ruled out

Menu