1 Encoding encoding = Encoding.GetEncoding("utf-8");
2 string URL = "http://192.168.1.115/cccn/test_post.php";
3 string postData = "username" + textBox1.Text.ToString() + "password" + textBox2.Text.ToString();
4 byte[] data = encoding.GetBytes(postData);
5 HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(URL);
6 myRequest.Method = "POST";
7 myRequest.ContentType = "application/x-www-form-urlencoded";
8 myRequest.ContentLength = data.Length;
9 Stream st = myRequest.GetRequestStream();
10 st.Write(data, 0, data.Length);
11 st.Close();
12 HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
13 Stream receiveStream = myResponse.GetResponseStream();
14 StreamReader readStream = new StreamReader(receiveStream, encoding);
15 char[] read = new char[256];
16 int count = readStream.Read(read, 0, 256);
17 String str = null;
18 while (count > 0)
19 {
20 str += new string(read, 0, count);
21 count = readStream.Read(read, 0, 256);
22 }
23 myResponse.Close();
24 readStream.Close();
- 5 回答
- 0 关注
- 497 浏览
添加回答
举报
0/150
提交
取消