我从一个网页到另一个做重定向和从第二页的另一个重定向到第三位。 我从没有在第二页上使用,但必须被转移到第三页的第一页imformation。 是否有可能与它的查询字符串作为查询字符串的第三页的URL发送到第二页。 下面是一个例子:
Response.Redirect("MyURL1?redi=MyURL2?name=me&ID=123");
我的问题是正在发送的URL作为查询字符串有两个查询字符串变量,所以怎样让系统知道之后有什么&是第二个URL的第二个变量而不是第一个URL的第二个变量? 谢谢。
你必须编码你通过在你的重定向URL参数的URL。 像这样:
MyURL = "MyURL1?redi=" + Server.UrlEncode("MyURL2?name=me&ID=123");
这将创建一个正确的URL没有双“?” 和“&”字符:
MyURL1?redi=MyURL2%3fname%3dme%26ID%3d123
请参阅MSDN: HttpServerUtility.UrlEncode方法
为了从该编码的网址提取您重定向URL必须使用HttpServerUtility.UrlDecode
再次把它变成一个正确的URL。
您的查询字符串应该是这样的:
MyURL1?redi=MyURL2&name=me&ID=123
检查: http://en.wikipedia.org/wiki/Query_string
你应该有一个? 签署和所有参数加入了与&。 如果参数值包含特殊字符,只是用urlencode他们。
我发现它有助于在发送之前编码为Base64查询字符串参数。 在某些情况下,这会有所帮助,如果您需要发送各种特殊字符。 它没有良好的调试字符串,但它会保护你从任何其他参数入门混合发送任何数据。
只要记住,谁是解析查询字符串对方也需要解析中的Base64访问原始输入。
using System.IO;
using System.Net;
static void sendParam()
{
// Initialise new WebClient object to send request
var client = new WebClient();
// Add the QueryString parameters as Name Value Collections
// that need to go with the HTTP request, the data being sent
client.QueryString.Add("id", "1");
client.QueryString.Add("author", "Amin Malakoti Khah");
client.QueryString.Add("tag", "Programming");
// Prepare the URL to send the request to
string url = "http://026sms.ir/getparam.aspx";
// Send the request and read the response
var stream = client.OpenRead(url);
var reader = new StreamReader(stream);
var response = reader.ReadToEnd().Trim();
// Clean up the stream and HTTP connection
stream.Close();
reader.Close();
}