请求url参数 [英] Request url parameter
问题描述
我有一个页面,我在这样的参数中收到一个网址:
I have a page where I am recieving an url in a parameter like this:
www.example.com?url=www.myurl.com?urlparameter1=hey
问题是当我尝试检索参数url"时,我只收到www.myurl.com"而不是www.myurl.com?urlparameter1=hey".接收网址的最佳方式是什么,是提取整个网址并删除 www.example.com 还是有更有效的方法?
The problem is that when I try to retrieve the parameter "url", I only receive "www.myurl.com" instead of "www.myurl.com?urlparameter1=hey". What is the best way to receive the url, is it to extract the whole url and remove www.example.com or is there a more efficient way?
推荐答案
您需要对您的 URL 参数进行 URL 编码,否则它将被视为单独的查询字符串参数.
You need to URL encode your URL parameter, otherwise it will be read as separate querystring parameters.
使用 HttpUtility.UrlEncode.
Use HttpUtility.UrlEncode.
这样做:string urlParameter = HttpUtility.UrlEncode("www.myurl.com?urlparameter1=hey");
Do this: string urlParameter = HttpUtility.UrlEncode("www.myurl.com?urlparameter1=hey");
这会给你:www.myurl.com%3furlparameter1%3dhey
That will give you: www.myurl.com%3furlparameter1%3dhey
http://msdn.microsoft.com/en-us/library/system.web.httputility.urlencode.aspx
这篇关于请求url参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!