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

2017-01-11 09:00 出处:360java.com 作者:360java 评论(
1 Encoding encoding = Encoding.GetEncoding(quot;utf-8quot;); 2 string URL = quot;http:/...
 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();
最佳答案

string postData = "username" + textBox1.Text.ToString() + "password" + textBox2.Text.ToString();

查查这里.

做WEB,既然也用到了post方法, 为啥不用javascript来提交, 还用asp.net的方法? 直接写成html, 利用javascript提交, 是最好的办法.

我试试

我是CS的呀.....

@莫问: 你说的有点道理 不过不是我想要的

@莫问: 

真的呀, 你那个数据拼接有误

分享到:
本文标签: c#, .net技术, post, http, httpwebreq

相关文章

发表评论愿您的每句评论,都能给大家的生活添色彩,带来共鸣,带来思索,带来快乐。

Copyright (C) 360java 360java.com, All Rights Reserved.

苏ICP备16022210号