Показать сообщение отдельно

  #4613  
Старый 13.10.2009, 07:57
Пуховой
Banned
Регистрация: 25.11.2007
Сообщений: 62
С нами: 9715564

Репутация: 89
По умолчанию

Код:
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://antigate.com/in.php',multi);
  http.free; multi.free;
  deletefile(filename);
  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
    sleep (5000);
    http:=tidhttp.create(nil);
    tmpstr:=http.get('http://antigate.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;
  end;
  result:='error_timeout';
end;
bmp12, Попробуйте функцию напрямую. В новом приложении.
 
Ответить с цитированием