使用HttpWebRequest向网站模拟上传数据
最近有个朋友离开IT行业二年的朋友说要实现用程序向某个网站的页面上传数据,他是意思是每天有几十条数据要在网站页面上填写,很烦,最好用程序来写。网站页面是用POST传递的,同时没有验证码之类的东东,只有一点限制就是5分种内不能填写二次记录。这一切都好办。
using System.Web;
using System.Net;
using System.Text;
using System.IO;
//创建对某个网站页面的请求
HttpWebRequest myRequest = (HttpWebRequest )WebRequest.Create("http://www.knowsky.com/a.asp")
//上传的数据,”TextBox1“这些东东是网站页面里的控件ID,如果要上传多个值也是用&来分隔
string postData="TextBox1="+this.textBox1.Text+"&TextBox2="+this.textBox2.Text+"
&TextBox3="+this.textBox3.Text+"&TextBox4="+this.textBox4.Text;
ASCIIEncoding encoding=new ASCIIEncoding();
byte[] byte1=encoding.GetBytes(postData);//最终编码后要上传的数据
// Set the content type of the data being posted.
myRequest.ContentType="application/x-www-form-urlencoded";
myRequest.Method="post";//post上传方式
// Set the content length of the string being posted.
myRequest.ContentLength=postData.Length;
Stream newStream=myRequest.GetRequestStream();
newStream.Write(byte1,0,byte1.Length);
一切就OK了,如果你想上传后看到网站的内容的话,可以在程序里放一个IE控件,使用
axWebBrowser1.Navigate("http://www.knowsky.com/a.asp");
axWebBrowser1.Refresh2();
相关文章
asp.net Page.EnableEventValidation 属性验证服务器控件的回发和回调事件出现的错误
Page.EnableEventValidation 属性验证服务器控件的回发和回调事件出现的错误前两天用jQuery做了一个包含DropDownList联动的页面,数据通过Ajax请求得到的。2010-10-10GridView的CheckBox列选择及多参数传递三步搞定
GridView的CheckBox列选择及多参数传递三步实现:GridView的列设置/全选的Js处理/后台对所选值的获取,操作步骤很详细,有利于新手学习,感兴趣的朋友可以了解下啊2013-01-01ASP.NET Core Zero使用Power Tool工具
这篇文章介绍了ASP.NET Core Zero使用Power Tool工具的方法,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2022-02-02ASP.NET Core应用JWT进行用户认证及Token的刷新方案
本文详细讲解了ASP.NET Core应用JWT进行用户认证及Token的刷新方案,文中通过示例代码介绍的非常详细。对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2021-12-12
最新评论