Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to encode strings (eg URL) I pass as a POST form parameter

Do I need to encode strings (eg URL) I pass as a POST form parameter?

Ie I want to pass a URL I have to my web application (ruby on rails) as one of the form parameters. So are there any potential characters in a URL/URI that would need to be encoded? Or perhaps rails would handle this anyway?

like image 949
Greg Avatar asked Sep 13 '25 02:09

Greg


1 Answers

Do I need to encode strings (eg URL) I pass as a POST form parameter?

That depends on what you're using to create/send your POST request. If you're directly creating the request body yourself, then yes you would have to URL-encode each parameter:

POST / HTTP/1.1
Content-Type: application/x-www-form-urlencoded

foo=bar&url=http://www.example.com/url?innerparameter1=1&innerparameter2=2

this is no good:innerparameter2 is actually a parameter of the outer form-encoded string. It would need encoding, which would look like:

foo=bar&url=http%3A//www.example.com/url%3Finnerparameter1%3D1%26innerparameter2%3D2

If, however, you are using something higher-level to make the POST request, and passing in some kind of mapping of parameter strings, I would expect that component to take care of the URL-encoding for you.

Code?

like image 166
bobince Avatar answered Sep 14 '25 18:09

bobince