现在的位置: 首页 > 综合 > 正文

用代码向网站提交数据

2013年08月07日 ⁄ 综合 ⁄ 共 719字 ⁄ 字号 评论关闭

用代码向网站提交数据

左直拳

 

可以用代码模拟浏览器向网站提交数据:

string sUrl = "http://。。。。";//目标网址

Uri target = new Uri(sUrl);

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(target);

 

req.ReadWriteTimeout = 10000;

req.Timeout = 10000;

req.MaximumAutomaticRedirections = 5;

req.MaximumResponseHeadersLength = 5;

req.AllowAutoRedirect = true;

//装扮成一个浏览器,欺骗那个网址

req.UserAgent = "Mozilla/6.0 (compatible; MSIE 6.0; Windows NT 5.1)";

 

req.Method = "POST";

req.ContentType = "application/x-www-form-urlencoded";

string postData = "voteid=15196&markinfo=0&checktype=2&op=69884";//传递的数据

byte[] arPostData = Encoding.UTF8.GetBytes(postData);

req.ContentLength = arPostData.Length;

Stream newStream = req.GetRequestStream();

newStream.Write(arPostData, 0, arPostData.Length);

newStream.Close();

 

如果目标网址需要输入验证码,则死翘翘。

 

抱歉!评论已关闭.