首页 新闻 赞助 找找看

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

0
悬赏园豆:10 [已解决问题] 解决于 2013-07-10 17:09
 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();
Aiolos丶M的主页 Aiolos丶M | 初学一级 | 园豆:153
提问于:2013-07-08 16:25
< >
分享
最佳答案
0

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

查查这里.

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

收获园豆:4
风浪 | 老鸟四级 |园豆:2996 | 2013-07-08 17:26

我试试

Aiolos丶M | 园豆:153 (初学一级) | 2013-07-09 08:56

我是CS的呀.....

Aiolos丶M | 园豆:153 (初学一级) | 2013-07-09 09:09

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

Aiolos丶M | 园豆:153 (初学一级) | 2013-07-10 17:08

@莫问: 

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

风浪 | 园豆:2996 (老鸟四级) | 2013-07-10 17:35
其他回答(2)
0

楼主好像是提交了数据,但是对于返回的数据也是放到了字符串中,然后也没有显示的操作啊

收获园豆:4
chenping2008 | 园豆:9836 (大侠五级) | 2013-07-08 22:26

显示的操作,应该是在网页中。。。

支持(0) 反对(0) Aiolos丶M | 园豆:153 (初学一级) | 2013-07-09 09:09

我在最后还有两条代码

  
            Form2 f = new Form2();
            f.Show();
支持(0) 反对(0) Aiolos丶M | 园豆:153 (初学一级) | 2013-07-09 10:06
0

你这是一个client端的应用程序吧? 我的理解是你想在本机通过client程序获取一个已经处理了你post数据的页面。

http://192.168.1.115/cccn/test_post.php 是怎么处理数据的呢?
不清楚php的机制,但如果你是想提交表单的话 post数据的格式应该是: "username" + textBox1.Text.ToString()= + "&password=" + textBox2.Text.ToString() 你可以用fiddler看一下你php页面自身post的数据格式是什么样的,然后照葫芦画瓢吧
收获园豆:2
Dino H.Y | 园豆:151 (初学一级) | 2013-07-10 14:35
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册