Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Delphi программирование > Работа с сетью в Delphi
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 01.04.2009, 12:37   #1
Terikon
Форумчанин
 
Регистрация: 22.02.2009
Сообщений: 174
Вопрос Добавить данные в поток

Подскажите как правильно прикрутить антикапчу, первый раз с ней столкнулся

куда этот код нужно вставить?

Код:
procedure TForm1.Button1Click(Sender: TObject);
Var
 tr : TstringList;
 s,t,sres:string;
 Captcha:TMemoryStream;

begin
tr:=TstringList.Create;
tr.Add('username=LOGIN');
tr.Add('password=PASS');
idhttp1.Post('http://www.sait/auth.php?action=doauth',tr);

s:=idHTTP1.Get('http://www.sait/map.php');
sres:=copy(s,pos('profile ',s)+72,length(s)-pos('profile ',s)+72);
sres:=copy(sres,2,pos('</a>',sres));
sres:=copy(sres,1,length(sres)-10);

captcha:=TMemoryStream.Create;
idhttp1.Get('http://www.sait/code.php?id='+sres,captcha);
captcha.SaveToFile('captcha.png');
Captcha.Free;
tr.Free;

s:=idHTTP1.Get('http://www.sait/rad.php');
sres:=copy(s,pos('123',s)+200,length(s)-pos('123',s)+200);
sres:=copy(sres,2,pos('44',sres));
sres:=copy(sres,1,length(sres)-85);
idhttp1.Get('http://www.sait/index.php?hte=work&id='+sres+'&code='+result); // сюда нужно отправить текст отгаданной капчи

КОД АНТИКАПЧИ

Код:
implementation

{$R *.dfm}
function recognize(filename: string; apikey: string; is_phrase: boolean; is_regsense: boolean; is_numeric: boolean; min_len: integer; max_len: integer): string;
var
ftype,tmpstr,captcha_id: String;
i: integer;
http: TIdHTTP;
multi: Tidmultipartformdatastream;
begin
if FileExists(filename)=false then begin result:='ERROR: file not found'; exit; end;

ftype:='image/pjpeg';
if strpos(Pchar(filename),'jpg')<>nil then ftype:='image/pjpeg';
if strpos(Pchar(filename),'gif')<>nil then ftype:='image/gif';
if strpos(Pchar(filename),'png')<>nil then ftype:='image/png';

multi:=Tidmultipartformdatastream.Create;
multi.AddFormField('method','post');
multi.AddFormField('key',apikey);
multi.AddFile('file',filename,ftype);
if is_phrase=true then multi.AddFormField('phrase','1');
if is_regsense=true then multi.AddFormField('regsense','1');
if is_numeric=true then multi.AddFormField('numeric','1');
if min_len>0 then multi.AddFormField('min_len',inttostr(min_len));
if max_len>0 then multi.AddFormField('max_len',inttostr(max_len));

http:=TIdHTTP.Create(nil);
tmpstr:=http.Post('http://anti-captcha.com/in.php',multi);
http.Free;
captcha_id:='';
if strpos(Pchar(tmpstr),'ERROR_')<>nil then begin result:=tmpstr; exit; end;
if strpos(Pchar(tmpstr),'OK|')<>nil then captcha_id:=AnsiReplaceStr(tmpstr,'OK|','');
if captcha_id='' then result:='ERROR: bad captcha id';
for i:=0 to 20 do
  begin
  Application.ProcessMessages;
  sleep(5000);
  http:=TIdHttp.Create(nil);
  tmpstr:=http.Get('http://anti-captcha.com/res.php?key='+apikey+'&action=get&id='+captcha_id);
  http.Free;
  if strpos(Pchar(tmpstr),'ERROR_')<>nil then begin result:=tmpstr; exit; end;
  if strpos(Pchar(tmpstr),'OK|')<>nil then
    begin
    result:=AnsiReplaceStr(tmpstr,'OK|','');
    exit;
    end;
  Application.ProcessMessages;
  end;
result:='ERROR_TIMEOUT';

end;

procedure TForm1.Button1Click(Sender: TObject);
begin

rsltedit.Text:='recognizing...';
Button1.Enabled:=false;
rsltedit.Text:=recognize(filenameedit.Text,apikeyedit.Text,false,false,false,0,0);
Button1.Enabled:=true;
end;

end.
Terikon вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Добавить в форму данные Romuald Microsoft Office Excel 2 13.02.2009 22:45
Поток Черничный Общие вопросы Delphi 5 27.09.2008 21:23
добавить к опред столбцу DbGrid данные furstenberg Компоненты Delphi 4 27.02.2008 20:15
Добавить данные в поле (в конец) John_chek БД в Delphi 6 20.08.2007 14:23