具体需求如下:
假设我要用一个程序模拟下面这个网址中《确定》按钮的功能:http://list.qq.com/cgi-bin/qf_invite?id=3ef0963350a0570a66a32f2d3dbffc75c190b23cc7690702此程序需要在短时间内多次模拟发送请求的操作。
但是它自从第三次起会要求输入验证码,甚至会直接提示操作频繁稍后再试。问题1:
能不能每次操作都不用输入验证码直接提交?
若能,怎么实现?问题2:
如何从它返回的提示输入验证码的页面中提取验证码图片?
因为根据验证码图片地址获取的话每次都会重新生成一个新的图片,将会导致验证失败。我当前使用的代码如下:string postData = "t=qf_booked_feedback&id=3ef0963350a0570a66a32f2d3dbffc75c190b23cc7690702&[email protected]";
//验证码
string verifycode_cn = txtVal.Text.Trim();
//如果输入了验证码
postData += verifycode_cn.Length > 0 ? "&verifycode_cn=" + verifycode_cn : ""; ASCIIEncoding encoding=new ASCIIEncoding();
byte[] data = encoding.GetBytes(postData);
// Prepare web request...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://list.qq.com/cgi-bin/qf_compose_send");
///测试代码
//CookieContainer mc = new CookieContainer();
//myRequest.CookieContainer = mc;
///测试结束
myRequest.Method = "POST";
myRequest.ContentType="application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream=myRequest.GetRequestStream();
// Send the data.
newStream.Write(data,0,data.Length);
newStream.Close();
// Get response
HttpWebResponse myResponse=(HttpWebResponse)myRequest.GetResponse(); StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.GetEncoding("utf-8"));
string content = reader.ReadToEnd();
reader.Close(); //测试用代码,查看结果
this.richTextBox1.AppendText(content);
this.webBrowser1.DocumentText = content;
假设我要用一个程序模拟下面这个网址中《确定》按钮的功能:http://list.qq.com/cgi-bin/qf_invite?id=3ef0963350a0570a66a32f2d3dbffc75c190b23cc7690702此程序需要在短时间内多次模拟发送请求的操作。
但是它自从第三次起会要求输入验证码,甚至会直接提示操作频繁稍后再试。问题1:
能不能每次操作都不用输入验证码直接提交?
若能,怎么实现?问题2:
如何从它返回的提示输入验证码的页面中提取验证码图片?
因为根据验证码图片地址获取的话每次都会重新生成一个新的图片,将会导致验证失败。我当前使用的代码如下:string postData = "t=qf_booked_feedback&id=3ef0963350a0570a66a32f2d3dbffc75c190b23cc7690702&[email protected]";
//验证码
string verifycode_cn = txtVal.Text.Trim();
//如果输入了验证码
postData += verifycode_cn.Length > 0 ? "&verifycode_cn=" + verifycode_cn : ""; ASCIIEncoding encoding=new ASCIIEncoding();
byte[] data = encoding.GetBytes(postData);
// Prepare web request...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://list.qq.com/cgi-bin/qf_compose_send");
///测试代码
//CookieContainer mc = new CookieContainer();
//myRequest.CookieContainer = mc;
///测试结束
myRequest.Method = "POST";
myRequest.ContentType="application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream=myRequest.GetRequestStream();
// Send the data.
newStream.Write(data,0,data.Length);
newStream.Close();
// Get response
HttpWebResponse myResponse=(HttpWebResponse)myRequest.GetResponse(); StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.GetEncoding("utf-8"));
string content = reader.ReadToEnd();
reader.Close(); //测试用代码,查看结果
this.richTextBox1.AppendText(content);
this.webBrowser1.DocumentText = content;
现读取验证码图片,然后根据该cookie去post