HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); 
                 request.Method = "POST";//这无论是赋post还是get,都必须用全大写,此值错一点,都会导致程序错误,因为不符合http协议 
request.ContentType = "multipart/form-data; boundary=--abc";//或者为"application/x-www-form-urlencoded",对应form标签里的 enctype属性,boundary那部分查是FORM元素各值的分隔符,具体请查阅HTTP协议相关文档,如果此值用application/x- www-form-urlencoded则form各元素用&来分隔,而元素的值是经过了url编码,调用System.Web.HttpUtility.UrlEncode方法,就能将值进行url编码。
//如果需要加cookie,则按如下方式添加,具体请参阅msdn 
request.CookieContainer = new CookieContainer(); request.CookieContainer.Add(new Cookie("test", "i love u", "/", "localhost")); byte[] data = Encoding.GetEncoding(encoding).GetBytes(postData);//将要发送的数据按HTTP协议拼装好字符串转成字节数组 
request.ContentLength = data.Length;//设置内容的长度,长度就是要发送的整个字节数组的长度,此句必须有,长度不对就会导致错误 
request.GetRequestStream().Write(data, 0, data.Length);//获取request的流,将数据写入流中,至此完成了form提交的必须有的步骤 
response = (HttpWebResponse)request.GetResponse();//最后取得response获取服务器端的返回数据进行处理
从 A.aspx用此方法提交数据,如何在B.aspx页面接收到这些数据?
用不用在A.aspx里面Response.Redirect("B.aspx");?

解决方案 »

  1.   

    在b.aspx 页面里直接用Request["参数名"]就可以获取到。 body的method设置为post提交,action设置为b.aspx
      

  2.   


    "参数名"从何而来?我在a.aspx页面里面<form id="form1" method="post" action="b.aspx" runat="server">运行自己生成的页面却变成了<form id="form1" method="post" action="a.aspx">
    也就是说不管action写什么都会生成a.aspx。还有你说的"参数名",我要做a.aspx 的什么地方定义?
      

  3.   

    在aspx页面用不着自己用httpwebrequest提交数据,默认服务器button控件提交到本页。
    如果要提交到其他页面,PostBackUrl="b.aspx"
      

  4.   

     StringBuilder sb = new StringBuilder();
            Encoding coding = Encoding.Default;
            StreamReader rdr = new StreamReader(Request.InputStream, coding);
            string line;
            while ((line = rdr.ReadLine()) != null)
            {
                sb.Append(line);
            }
            Response.ContentEncoding = coding;        Response.Write(sb.ToString());
    我在b.aspx页面里面接收,结果在a.aspx页面点击完之后,直接把b.aspx页面的内容都显示出来了。
      

  5.   

    postData的内容是什么啊?
    自己组织postData的内容啊,postData="userID=a001&userName=Jim"
    然后再B页面取
    Request.Form["userID"]
    Request.Form["userName"]