ITPub博客

首页 > > > 为啥网页不显示post传入的数据

为啥网页不显示post传入的数据

作者:R-B 时间:2019-10-14 11:35:16 0 删除 编辑
 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();


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4560/viewspace-3127059/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-09-03

  • 博文量
    183
  • 访问量
    10155