将url作为url参数传递的推荐方法是什么? [英] What is the recommended way to pass urls as url parameters?

查看:455
本文介绍了将url作为url参数传递的推荐方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用& url ='+ encodeURIComponent(url); 将URL从浏览器传递到服务器将对url进行编码,但是当它在服务器上解码时, url的参数被解释为单独的参数,而不是单个url参数的一部分。

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.

将url作为url参数传递的推荐方法是什么?

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

推荐答案

encodeURIComponent()应该有效。例如,

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

产生

"&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"

我不确定你正在使用什么服务器(例如Rails,Django,......),但这应该在任何正常系统上开箱即用。

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.

这篇关于将url作为url参数传递的推荐方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆