日期:2014-05-18 浏览次数:20755 次
string url = "http://localhost:/Activex/Serverpage.aspx"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); string Data = "Data=测试数据"; byte[] b = System.Text.Encoding.Default.GetBytes(Data); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = b.Length; Stream sw = request.GetRequestStream(); sw.Write(b, 0, b.Length); //写入数据 sw.Close(); try { HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream sw1 = response.GetResponseStream(); StreamReader sr = new StreamReader(sw1, System.Text.Encoding.Default); MessageBox.Show(sr.ReadToEnd()); //在这里输入发送后,页面返回的结果 sr.Close(); } catch (System.Net.WebException ex) { MessageBox.Show(ex.Status.ToString()); }