HTTP get、post请求

Post请求:

 1    string postData = "user=123&pass=456"; // 要发放的数据 
 2    byte[] byteArray = Encoding.UTF8.GetBytes(postData);
 3 
 4    HttpWebRequest objWebRequest = (HttpWebRequest)WebRequest.Create("http://www.abc.com/a.aspx");
 5    objWebRequest.Method = "POST";
 6    objWebRequest.ContentType = "application/x-www-form-urlencoded";
 7    objWebRequest.ContentLength = byteArray.Length;
 8    Stream newStream = objWebRequest.GetRequestStream();
 9    // Send the data. 
10    newStream.Write(byteArray, 0, byteArray.Length); //写入参数 
11    newStream.Close();
12 
13    HttpWebResponse response = (HttpWebResponse)objWebRequest.GetResponse();
14    StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.Default);
15    string textResponse = sr.ReadToEnd(); // 返回的数据

 

接收参数:string a= Request.Form["user"];

posted @ 2016-06-06 16:48  Dukezhou  阅读(278)  评论(0编辑  收藏  举报