怎样通过HttpWebRequest 发送 POST 请求到一个网页服务器?例如编写个程序实现自动用户登录,自动提交表单数据到网站等。
假如某个页面有个如下的表单(Form):
<form name="form1" action="http://www.here.com/login.asp" method="post">
<input type="text" name="userid" value="">
<input type="password" name="password" value="">
</form>
用C#写提交程序: string strId = "guest";
string strPassword= "123456"; ASCIIEncoding encoding=new ASCIIEncoding();
string postData="userid="+strId;
postData += ("&password="+strPassword);
byte[] data = encoding.GetBytes(postData);
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("http://www.here.com/login.asp");
myRequest.Method = "POST";
myRequest.ContentType="application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream=myRequest.GetRequestStream();
newStream.Write(data,0,data.Length);
newStream.Close();
我用axWebBrowser1看,为什么提交不成功?数据没有post进去。
假如某个页面有个如下的表单(Form):
<form name="form1" action="http://www.here.com/login.asp" method="post">
<input type="text" name="userid" value="">
<input type="password" name="password" value="">
</form>
用C#写提交程序: string strId = "guest";
string strPassword= "123456"; ASCIIEncoding encoding=new ASCIIEncoding();
string postData="userid="+strId;
postData += ("&password="+strPassword);
byte[] data = encoding.GetBytes(postData);
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("http://www.here.com/login.asp");
myRequest.Method = "POST";
myRequest.ContentType="application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream=myRequest.GetRequestStream();
newStream.Write(data,0,data.Length);
newStream.Close();
我用axWebBrowser1看,为什么提交不成功?数据没有post进去。
解决方案 »
- System.Timer.Timer的lock争用问题
- 各位请问:后台生成的A标记 怎样调用onserverclick事件
- Response.Redirect 后怎么打开新的ShowSearchInfo.aspx页
- 关于文件编码的问题
- sql在程序中执行无响应,在sqlplus执行很好???
- 关于C#中接口和static关键字的疑问
- C#小问
- C#下COM+的问题
- 远程对象在客户机上积极拒绝(但远程访问没有问题)
- IE8 中"HTML Parsing Error:Unable to modify the parent container element before th
- 问个比较弱的问题,C#和SQL Server的
- 怎样使程序在托盘区内得图标总是显示
用xmlhttp好点