我想将它集成到 Windows 应用程序中。我正在使用 Visual Studio 2010,它是一个 C# Windows 窗体应用程序。
问问题
3508 次
1 回答
5
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;
}
}
像这样使用它:
string challenge = null; // you will need this to submit captcha answer
pictureBox1.Image = DownloadReCaptcha("reCaptcha site key", ref challenge);
如何找到钥匙?
在网页的 HTML 源代码中,您会发现类似
<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=6LexLsMSAAAAABUuI6bvUYfxaumgcu0vGiEFotDA"></script>
key = 6LexLsMSAAAAABUuI6bvUYfxaumgcu0vGiEFotDA
于 2013-02-14T17:52:59.557 回答