I'm trying to write a Java class to log in to a certain website. The data sent in the POST request to log in is
user%5Blogin%5D=username&user%5Bpassword%5D=123456
I'm curious what the %5B
and %5D
means in the key user login.
How do I encode these data?
This question is related to
java
post
httpwebrequest
They represent [
and ]
. The encoding is called "URL encoding".
Not least important is why these symbols occur in url. See https://www.php.net/manual/en/function.parse-str.php#76792, specifically:
parse_str('foo[]=1&foo[]=2&foo[]=3', $bar);
the above produces:
$bar = ['foo' => ['1', '2', '3'] ];
and what is THE method to separate query vars in arrays (in php, at least).
To take a quick look, you can percent-en/decode using this online tool.
[]
is replaced by %5B%5D
at URL encoding time.
Well it's the usual url encoding
So they stand for [
, respectively ]
The data would probably have been posted originally from a web form looking a bit like this (but probably much more complicated):
<form action="http://example.com" method="post">
User login <input name="user[login]" /><br />
User password <input name="user[password]" /><br />
<input type="submit" />
</form>
If the method were "get" instead of "post", clicking the submit button would take you to a URL looking a bit like this:
http://example.com/?user%5Blogin%5D=username&user%5Bpassword%5D=123456
or:
http://example.com/?user[login]=username&user[password]=123456
The web server on the other end will likely take the user[login]
and user[password]
parameters, and make them into a user
object with login
and password
fields containing those values.
Source: Stackoverflow.com