NSE*_*ion 8 macos captcha objective-c
我正在开发一个Mac OS X应用程序,它具有从CAPTCHA图像读取/提取文本的概念.我在谷歌搜索并获得了一个名为"DeathByCaptcha"的API,它完全符合我的要求但是这个API不适用于Mac OS X,这个API可用于.Net/C/PHP/Python等.
'DeathByCaptcha'可以在网上找到.我在搜索时发现了这个Stack Overflow的帖子,但这并没有读取CAPTCHA图像,它只是读取一个简单的图像并转换成文本.
请帮我从使用Objective-C的CAPTCHA图像中为Mac OS X应用程序提取文本.
大家好,我编写了下面的代码来解决我的验证码问题,它对我来说非常有用。
从验证码图像读取文本的代码
您将需要 ASIHTTPRequest API 在网络上发送 HTTP 请求并获取以下代码的响应。
将 ASIHTTPRequest API 的相应类导入到您要执行从验证码图像中获取文本的过程的类中。
现在使用下面的方法并调用来解决catpcha。
-(NSString *)CaptchaToText
{
// Captcha Image Url in NSData object
NSData *urlData=[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://oi47.tinypic.com/357hyea.jpg"]];
// base64 image data
NSString *imageBase64Data = [ASIHTTPRequest base64forData:urlData ];
//NSString *imageBase64Data =[self base64EncodedString:urlData];
NSLog(@"imageBase64Data =%@\n\n",imageBase64Data);
// prefix - base64 image data
NSString *prefixBase64Data = [NSString stringWithFormat:@"base64:%@",imageBase64Data];
NSLog(@"prefixBase64Data Value = %@\n\n",prefixBase64Data);
ASIHTTPRequest *req=[ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://oi47.tinypic.com/357hyea.jpg"]];
[req startSynchronous];
NSError *err=[req error];
if(!err){
NSString *respo=[req responseString];
NSLog(@"respo= %@",respo);
NSURL *url = [NSURL URLWithString:@"http://api.dbcapi.me/api/captcha"];
ASIFormDataRequest *request=[ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"YourDeathByCaptchaUserName" forKey:@"username"];
[request setPostValue:@"YourDeathByCaptchaPassword!@#$" forKey:@"password"];
[request setPostValue:prefixBase64Data forKey:@"captchafile"];
[request setRequestMethod:@"POST"];
[request startSynchronous];
NSError *error=[request error];
if(!error){
// Here we will get "Text" data from Captcha Image in "response"
NSString *response=[request responseString];
NSLog(@"response= %@",response);
}
else{
NSLog(@"error= %@",error);
}
}
else{
NSLog(@"err= %@",err);
}
return response;
}
Run Code Online (Sandbox Code Playgroud)
就是这样。完毕
归档时间: |
|
查看次数: |
2334 次 |
最近记录: |