日期:2014-05-17  浏览次数:20445 次

url传值,字符串过长,怎么能全部传过去?
我想用js的url传值的方法把一个xml字符串传到另外一个页面后台,怎么传能把该xml全传过去?
例如 window.location.href = "WorkFlow/WorkFlowList.aspx?XmlText='" + b + "'";b是xml字符串,太长了,怎么传过去?

------解决方案--------------------
传值方法很多,可以考虑用别的。非要用url的话,可以只传一个标识,新窗口中根据这个标识去加载内容,标识和内容,类似key和value的关系。
------解决方案--------------------
表单传值
<form id='form1' method='pst' action='WorkFlow/WorkFlowList.aspx'>
<input type='hidden' name='XmlText'/>
</form>
js提交表单前把hidden的value赋值为b,然后submit.

也可以考虑ajax、拼接发送报文……原理都是一样,走post
------解决方案--------------------
post传值
C# code

        protected void Page_Load(object sender, EventArgs e)
        {
            string strUrl = Request.Url.ToString().Substring(0, Request.Url.ToString().LastIndexOf('/')) + "/WebForm1.aspx";
            ASCIIEncoding code = new ASCIIEncoding();
            string postData = "aa=iceapple.net&bb=yibin.net"; //这是要post的数据 
            byte[] data = code.GetBytes(postData);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strUrl);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded"; //这里的ContentType很重要! 
            request.ContentLength = data.Length;
            using (Stream stream = request.GetRequestStream()) //获取数据流,该流是可写入的 
            {
                stream.Write(data, 0, data.Length); //发送数据流 
                stream.Close();
            }

            HttpWebResponse res = (HttpWebResponse)request.GetResponse();
            StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);
            string backstr = sr.ReadToEnd();
            Response.Write(backstr);
            sr.Close();
            res.Close();

        }