我可以在Windows应用程序,而不是在网页中包括验证码? [英] Can I include reCAPTCHA in a Windows application instead of in a webpage?
本文介绍了我可以在Windows应用程序,而不是在网页中包括验证码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将它集成到Windows应用程序。我使用Visual Studio 2010中,它是一个C#Windows窗体应用程序。
解决方案
公共静态图像DownloadReCaptcha(字符串键,裁判串挑战)
{
尝试
{
Web客户端的客户端=新的Web客户端();
字符串响应= client.DownloadString(的String.Format(http://api.recaptcha.net/challenge?k={0}键));
比赛比赛= Regex.Match(回应,挑战:'?(+)');
如果(match.Captures.Count == 0)
{
挑战= NULL;
返回null;
}
挑战= match.Groups [1] .value的;
如果(File.Exists(captcha.jpg))File.Delete(captcha.jpg);
client.DownloadFile(的String.Format(http://www.google.com/recaptcha/api/image?c={0},挑战),
captcha.jpg);
返回Image.FromFile(captcha.jpg);
}
赶上(例外)
{
挑战= NULL;
返回null;
}
}
使用它像:
字符串的挑战= NULL; //你需要这个提交验证码答案
pictureBox1.Image = DownloadReCaptcha(验证码网站键,裁判的挑战);
如何找到问题的关键?
在网页的HTML源代码,你会发现像
&LT;脚本类型=文/ JavaScript的 src="http://www.google.com/recaptcha/api/challenge?k=6LexLsMSAAAAABUuI6bvUYfxaumgcu0vGiEFotDA"></script>$c$c>
键= 6LexLsMSAAAAABUuI6bvUYfxaumgcu0vGiEFotDA
I'd like to integrate it into a Windows application. I'm using Visual Studio 2010 and it is a C# Windows Forms application.
解决方案
public static Image DownloadReCaptcha(string key, ref string challenge)
{
try
{
WebClient client = new WebClient();
string response = client.DownloadString(string.Format("http://api.recaptcha.net/challenge?k={0}", key));
Match match = Regex.Match(response, "challenge : '(.+?)'");
if (match.Captures.Count == 0)
{
challenge = null;
return null;
}
challenge = match.Groups[1].Value;
if (File.Exists("captcha.jpg")) File.Delete("captcha.jpg");
client.DownloadFile(string.Format("http://www.google.com/recaptcha/api/image?c={0}", challenge),
"captcha.jpg");
return Image.FromFile("captcha.jpg");
}
catch (Exception)
{
challenge = null;
return null;
}
}
Use it like :
string challenge = null; // you will need this to submit captcha answer
pictureBox1.Image = DownloadReCaptcha("reCaptcha site key", ref challenge);
How to find the key ?
In the HTML source of web-page you will find something like
<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=6LexLsMSAAAAABUuI6bvUYfxaumgcu0vGiEFotDA"></script>
key = 6LexLsMSAAAAABUuI6bvUYfxaumgcu0vGiEFotDA
这篇关于我可以在Windows应用程序,而不是在网页中包括验证码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文