怎么用 POST 传参并打开页面??

helloworld84 2005-11-22 03:13:51
在 WinForm 用下面的方法可以打开页面并同时通过 GET 传参实现自动登录,我想知道如果采用POST方式传参这段代码该怎么改..

string s = "http://www.xxx.com/send.aspx?user=aaa&pass=bbb";
System.Diagnostics.Process.Start(s)
...全文
543 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
fffgtao 2006-04-03
  • 打赏
  • 举报
回复
收录
helloworld84 2005-11-23
  • 打赏
  • 举报
回复
很好,谢谢,先研究一下这个小助手再说
Qqwwee_Com 2005-11-23
  • 打赏
  • 举报
回复
1.发送的地址是不是正确的
2.发送的数据不是完整的
3.Cookie之类的东西
4.其他的限制比如Referance

最保险的方式:找个抓包软件抓取在浏览器里面的http包,然后比较自己程序的数据包,看看区别是哪里

你可以看看我的尾巴后面的软件


#region 广告开始

CSDN小助手 V2.5,更快、更爽、更方便的浏览CSDN论坛!
界面:http://blog.csdn.net/Qqwwee_Com/archive/2005/11/05/523395.aspx
下载:http://szlawbook.com/csdnv2

***
我们每回答一个问题,
就谋杀了提问者一个思考的机会,
而这个思考的机会可能让他获得10倍的知识,
所以,我们不下地狱谁下地狱?
***

#endregion
helloworld84 2005-11-23
  • 打赏
  • 举报
回复
楼上的方法都试过了,还是传不过去,还有,我测试传递的页面并不是 ASPX 页面, 而是 ASP 跟 PHP, 这有关系吗?
netsapper 2005-11-23
  • 打赏
  • 举报
回复
private HttpWebRequest CreateRequest()
{

HttpWebRequest 请求=null;
// string aa=TxNetId();

请求=(HttpWebRequest)HttpWebRequest.Create(this._strUrl);//创建请求
请求.Accept = "*/*"; //接受任意文件
请求.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.1.4322)"; // 模拟使用IE在浏览
请求.AllowAutoRedirect = true;//这里不允许302
请求.CookieContainer =comm.cookie;//cookie容器,
请求.Referer="http://bbs.tiexue.net"; //当前页面的引用


//如果附带cookie 就发送
if ( this._cookiePost !=null)
{
System.Uri u =new Uri(_strUrl);
//doenet处理cookie的bug:请求的服务器和cookie的Host必须一直,否则不发送或获取!

//这里修改成一致!
foreach(System.Net.Cookie c in _cookiePost)
{
c.Domain= u.Host;
}

请求.CookieContainer.Add(_cookiePost);
}

//如果需要发送数据,就以Post方式发送
if (_strPostdata !=null && _strPostdata.Length>0)
{
// 请求.CookieContainer.Add(new Cookie("TxNet","","/","bbs.tiexue.net"));
请求.ContentType = "application/x-www-form-urlencoded";//作为表单请求
请求.Method = "POST";//方式就是Post

//发送http数据:朝请求流中写post的数据
byte[] b= this._encoding.GetBytes(this._strPostdata);
请求.ContentLength=b.Length;
System.IO.Stream sw=null;
try
{
sw=请求.GetRequestStream();
sw.Write(b,0,b.Length );
}
catch (System.Exception ex)
{
this._strErr=ex.Message;
}
finally
{
if (sw!=null){sw.Close();}
}

}
return 请求; //返回创建的请求对象

}

public string Proc()
{

HttpWebRequest 请求=CreateRequest();//请求
HttpWebResponse 响应=null;;

System.IO.StreamReader sr=null;


try
{
//这里得到响应

响应 =(HttpWebResponse)请求.GetResponse();

sr=new System.IO.StreamReader(响应.GetResponseStream(),this.encoding);

this._ResHtml=sr.ReadToEnd(); // 这里假定响应的都是html文本
}
catch (System.Exception ex)
{
this._strErr=ex.Message;//发生错误就返回空文本
return "";
}
finally
{
if (sr!=null){sr.Close();}
}
//状态码
this._strCode=响应.StatusCode.ToString();

if (this._strCode=="302") //如果是302重定向的话就返回新的地址。
{
this._ResHtml=响应.Headers["location"];
}

//得到cookie
if( 响应.Cookies.Count > 0)
{
this._cookieGet =响应.Cookies; //得到新的cookie:注意这里没考虑cookie合并的情况
}
return this.ResHtml ;
}
helloworld84 2005-11-22
  • 打赏
  • 举报
回复
楼上提供的这个也没看到什么有建设性的东西啊
hanmlxiao 2005-11-22
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/4302/4302189.xml?temp=.9401972
helloworld84 2005-11-22
  • 打赏
  • 举报
回复
上面的方法都试过了,都没有传递成功,打开后都是没有登录,没有人做过类似的实例吗?
syeerzy 2005-11-22
  • 打赏
  • 举报
回复
new 一个 HttpWebRequest 对象,再设置各项参数属性.

没试过在WinForm中这么做,不过照理应该可以,不可以的话也别怪我....猜测而已.
孟子E章 2005-11-22
  • 打赏
  • 举报
回复
代码类似
http://dotnet.aspx.cc/ShowDetail.aspx?id=ATV1GLXT-65FF-4M82-CT5U-B1J65D3ZN2OK

110,571

社区成员

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

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

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