我想将它集成到Windows应用程序中。 我正在使用Visual Studio 2010,它是一个C#Windows窗体应用程序。
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