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;
}
}
Run Code Online (Sandbox Code Playgroud)
使用它像:
string challenge = null; // you will need this to submit captcha answer
pictureBox1.Image = DownloadReCaptcha("reCaptcha site key", ref challenge);
Run Code Online (Sandbox Code Playgroud)
在网页的HTML源代码中,你会发现类似的内容
<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=6LexLsMSAAAAABUuI6bvUYfxaumgcu0vGiEFotDA"></script>
key = 6LexLsMSAAAAABUuI6bvUYfxaumgcu0vGiEFotDA
| 归档时间: |
|
| 查看次数: |
2427 次 |
| 最近记录: |