Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the recommended way to pass urls as url parameters?

Tags:

javascript

Using &url='+encodeURIComponent(url); to pass a URL from browser to server will encode the url but when it is decoded at the server, the parameters of url are interpreted as seperate parameters and not as part of the single url parameter.

What is the recommended way to pass urls as url parameters ?

like image 709
Nir Avatar asked Nov 15 '09 16:11

Nir


People also ask

How do you send a URL as a URL parameter?

Using &url='+encodeURIComponent(url); to pass a URL from browser to server will encode the url but when it is decoded at the server, the parameters of url are interpreted as seperate parameters and not as part of the single url parameter.

Is it safe to pass parameters in URL?

URLS and query parameters aren't secure. They should never contain sensitive or important information (passwords, static shared secrets, private information, etc).

Which is the recommended way to prevent URL query parameters?

One way to remove query parameters from pages is through the View Settings. Under Admin > View Settings > Exclude Query Parameters, list the query parameters that you want to exclude from your page paths.

In which method parameters are passed in URL?

The getParameter() method is the HTTP request method most often used to request resources from a server through a client such as a browser. Since the transmitted page contents or files are requested using URLs, an indication of URL parameters is also important.


2 Answers

encodeURIComponent() should work. For example,

'&url=' + encodeURIComponent("http://a.com/?q=query&n=10") 

produces

"&url=http%3A%2F%2Fa.com%2F%3Fq%3Dquery%26n%3D10" 

(which doesn't have any & or ? in the value). When your server gets this url, it should be able to decode that to get the original:

param["url"] = "http://a.com/?q=query&n=10" 

I'm not sure what server you're using (e.g. Rails, Django, ...) but that should work "out of the box" on any normal system.

like image 166
2 revs, 2 users 93% Avatar answered Sep 24 '22 00:09

2 revs, 2 users 93%


Using '&url='+encodeURIComponent(url); to pass a URL from browser to server will encode the url

Yes, that's what you should be doing. encodeURIComponent is the correct way to encode a text value for putting in part of a query string.

but when it is decoded at the server, the parameters of url are interpreted as seperate parameters and not as part of the single url parameter.

Then the server is very broken indeed. If that's really what's happening, you need to fix it at the server end.

Code?

like image 38
bobince Avatar answered Sep 21 '22 00:09

bobince