当前位置: 移动技术网 > IT编程>开发语言>.net > 使用HttpWebRequest向网站模拟上传数据

使用HttpWebRequest向网站模拟上传数据

2018年04月28日  | 移动技术网IT编程  | 我要评论

贵州卫视养生堂,变身恐龙大战无敌版,电视节目参数

最近有个朋友离开it行业二年的朋友说要实现用程序向某个网站的页面上传数据,他是意思是每天有几十条数据要在网站页面上填写,很烦,最好用程序来写。网站页面是用post传递的,同时没有验证码之类的东东,只有一点限制就是5分种内不能填写二次记录。这一切都好办。

using system.web;
using system.net;
using system.text;
using system.io;

//创建对某个网站页面的请求

httpwebrequest  myrequest = (httpwebrequest )webrequest.create("")

//上传的数据,”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("");
axwebbrowser1.refresh2();

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网