(100分急求)关于webBrowser.Navigate post数据的问题

wujiche 2010-04-27 10:58:29
我用webBrowser控件做了个浏览器,我想用webBrowser.Navigate方法中postdata[]参数post数据到服务器,代码如下
byte[] btPost = new byte[] { };
btPost = System.Text.Encoding.ASCII.GetBytes("ssss");
MwebBrowser.Navigate("http://localhost:1137/yd_website/Layout/Login.aspx","",btPost,"");
但是我不知道在网页中怎么接收传过来的post数据,并且我不太清楚上面的post方法对不对,请哪位大侠在asp.net网页后台接收post过来数据的代码!!!!!!!!!!
...全文
620 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
libailin 2010-05-18
  • 打赏
  • 举报
回复
如何,处理MwebBrowser.Navigate返回值

还没根本没有返回!

Justin-Liu 2010-04-27
  • 打赏
  • 举报
回复
UPUP JF haha
a82344626 2010-04-27
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 a82344626 的回复:]
C# code

HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create("页面");
hwr.KeepAlive = true;
hwr.Method = "post";

byte[] requestBytes = System……
[/Quote]
这个写成个方法
你还没看出有返回值吗?
wujiche 2010-04-27
  • 打赏
  • 举报
回复
哎自己搞定了。。其实很简单浏览器那边写代码如下
byte[] btPost = new byte[] { };
btPost = System.Text.Encoding.ASCII.GetBytes("yes");
MwebBrowser.Navigate("http://localhost/fff/Default.aspx", "", btPost, "");

在asp.net网页那边接受代码如下
StreamReader sr = new StreamReader(Request.InputStream, Encoding.Default);
string textResponse = sr.ReadToEnd(); // 返回的数据
TextBox1.Text = textResponse;
wujiche 2010-04-27
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 a82344626 的回复:]
C# code

System.IO.TextReader tr = new System.IO.StreamReader(上面的方法);
string str = tr.ReadToEnd();//返回的数据
[/Quote]

接收端的方法怎么写“(上面的方法)“什么意思
a82344626 2010-04-27
  • 打赏
  • 举报
回复

System.IO.TextReader tr = new System.IO.StreamReader(上面的方法);
string str = tr.ReadToEnd();//返回的数据

a82344626 2010-04-27
  • 打赏
  • 举报
回复

HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create("页面");
hwr.KeepAlive = true;
hwr.Method = "post";

byte[] requestBytes = System.Text.Encoding.UTF8.GetBytes("POST的数据");
hwr.ContentLength = requestBytes.Length;
System.IO.Stream sw = null;
HttpWebResponse hwrp = null;
try
{
sw = hwr.GetRequestStream();
sw.Write(requestBytes, 0, requestBytes.Length);
hwrp = (HttpWebResponse)hwr.GetResponse();

}
catch (Exception)
{

}
finally
{
if (sw != null)
{
sw.Close();
sw.Dispose();
}

}
if (hwrp == null)
{

}
if (hwrp.StatusCode == HttpStatusCode.OK)
{

return hwrp.GetResponseStream();
}
throw new Exception("连接错误");
wujiche 2010-04-27
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 yuanhuiqiao 的回复:]
是这个?

C# code
string postData = "user=123&pass=456"; // 要发放的数据
byte[] byteArray = Encoding.UTF8.GetBytes(postData);

HttpWebRequest objWebRequest = (HttpWebRequest)WebRequest.Create("http://……
[/Quote]

运行好像不行
yuanhuiqiao 2010-04-27
  • 打赏
  • 举报
回复
是这个?
string postData = "user=123&pass=456"; // 要发放的数据
byte[] byteArray = Encoding.UTF8.GetBytes(postData);

HttpWebRequest objWebRequest = (HttpWebRequest)WebRequest.Create("http://www.abc.com/a.aspx");
objWebRequest.Method = "POST";
objWebRequest.ContentType = "application/x-www-form-urlencoded";
objWebRequest.ContentLength = byteArray.Length;
Stream newStream = objWebRequest.GetRequestStream();
// Send the data.
newStream.Write(byteArray, 0, byteArray.Length); //写入参数
newStream.Close();

HttpWebResponse response = (HttpWebResponse)objWebRequest.GetResponse();
StreamReader sr=new StreamReader(response.GetResponseStream(), Encoding.Default);
string textResponse = sr.ReadToEnd(); // 返回的数据
捷哥1999 2010-04-27
  • 打赏
  • 举报
回复
顶一个!
lpingz 2010-04-27
  • 打赏
  • 举报
回复
没做过,帮顶。

110,556

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧