日期:2014-05-17 浏览次数:20445 次
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(); }