110,536
社区成员
发帖
与我相关
我的任务
分享
void PostMe(object sender, EventArgs e){
string poststring = String.Format("field1={0}&field2={1}",text1.Text,text2.Text);
ResponseResult.Text = "<hr/>" +
GetResponseString("http://www.jigar.net/demo/HttpRequestDemoServer.aspx",poststring);
}
String GetResponseString(string url, string poststring){
HttpWebRequest httpRequest =
(HttpWebRequest)WebRequest.Create("http://www.jigar.net/demo/HttpRequestDemoServer.aspx");
httpRequest.Method = "POST";
httpRequest.ContentType = "application/x-www-form-urlencoded";
byte[] bytedata = Encoding.UTF8.GetBytes(poststring);
httpRequest.ContentLength = bytedata.Length;
Stream requestStream = httpRequest.GetRequestStream();
requestStream.Write(bytedata, 0, bytedata.Length);
requestStream.Close();
HttpWebResponse httpWebResponse =
(HttpWebResponse)httpRequest.GetResponse();
Stream responseStream = httpWebResponse.GetResponseStream();
StringBuilder sb = new StringBuilder();
using (StreamReader reader =
new StreamReader(responseStream, System.Text.Encoding.UTF8))
{
string line;
while ((line = reader.ReadLine()) != null)
{
sb.Append(line);
}
}
return sb.ToString();
}