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

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

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

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

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

Ответ
 
Опции темы Поиск в этой теме
Старый 02.10.2017, 21:26   #1
alex0097
Форумчанин
 
Аватар для alex0097
 
Регистрация: 06.07.2010
Сообщений: 123
По умолчанию Http Get

Здравствуйте. Подскажите как отправить несколько запросов что бы он вставил в каждый label отдельно?

Код:
procedure TForm1.Button1Click(Sender: TObject);
var
s:widestring;
begin
S:= TKOLHttp.get('http://site.ru//1.txt');
Form1.label1.Caption:='Параметр :'+ S; 
I:= TKOLHttp.get('http://site.ru//2.txt');
Form1.label2.Caption:='Параметр :'+ I; 
P:= TKOLHttp.get('http://site.ru//3.txt');
Form1.label3.Caption:='Параметр :'+ P; 
end;
Пробовал так. Ошибка:
Код:
[DCC Error] Unit1.pas(537): E2010 Incompatible types: 'string' and 'procedure, untyped pointer or untyped parameter'

Последний раз редактировалось alex0097; 02.10.2017 в 21:38.
alex0097 вне форума Ответить с цитированием
Старый 02.10.2017, 21:34   #2
Serge_Bliznykov
Старожил
 
Регистрация: 09.01.2008
Сообщений: 26,229
По умолчанию

так?
Код:
procedure TForm1.Button1Click(Sender: TObject);
var
  S:widestring;
begin
  S:= Idhttp1.get('http://site.ru//1.txt');
  label1.Caption:='Параметр :'+ S; 
  S:= Idhttp1.get('http://site.ru//2.txt');
  label2.Caption:='Параметр :'+ S; 
  S:= Idhttp1.get('http://site.ru//3.txt');
  label3.Caption:='Параметр :'+ S; 
end;
Serge_Bliznykov вне форума Ответить с цитированием
Старый 02.10.2017, 21:37   #3
alex0097
Форумчанин
 
Аватар для alex0097
 
Регистрация: 06.07.2010
Сообщений: 123
По умолчанию

Цитата:
Сообщение от Serge_Bliznykov Посмотреть сообщение
так?
Код:
procedure TForm1.Button1Click(Sender: TObject);
var
  S:widestring;
begin
  S:= Idhttp1.get('http://site.ru//1.txt');
  label1.Caption:='Параметр :'+ S; 
  S:= Idhttp1.get('http://site.ru//2.txt');
  label2.Caption:='Параметр :'+ S; 
  S:= Idhttp1.get('http://site.ru//3.txt');
  label3.Caption:='Параметр :'+ S; 
end;
Забыл упомянуть работаю с KOL а не INDI
с обычным thttp работает. а вот с TKOLHttp нет
alex0097 вне форума Ответить с цитированием
Старый 02.10.2017, 21:55   #4
Alex11223
Старожил
 
Аватар для Alex11223
 
Регистрация: 12.01.2011
Сообщений: 19,500
По умолчанию

Так посмотрите какие параметры и т.п. у функции.
Ушел с форума, https://www.programmersforum.rocks, alex.pantec@gmail.com, https://github.com/AlexP11223
ЛС отключены Аларом.
Alex11223 вне форума Ответить с цитированием
Старый 02.10.2017, 22:28   #5
alex0097
Форумчанин
 
Аватар для alex0097
 
Регистрация: 06.07.2010
Сообщений: 123
По умолчанию

вообще ни чего в голову не лезет. Подскажите пожалуйста
Код:
unit KOLHttp;

interface

uses
  Windows, KOL, KOLSocket;

type

  TKOLhttp        =^TKOLhttpControl;
  PKOLhttpControl =^TKOLhttpControl;
  TKOLhttpControl = object(TObj)
  private
   fAdr: string;
   fUrl: string;
   fRef: string;
   fUsr: string;
   fPas: string;
   fMth: string;
   fPAd: string;
   fPPr: integer;
   fCod: integer;
   fCnl: integer;
   Body: boolean;
   fHdr: PStrList;
   fCnt: PStrList;
   fSoc: PAsyncSocket;
  fPort: integer;
  fOnClos: TOnEvent;
  procedure OnDumm(Sender: TWMSocket);
  procedure OnConn(Sender: TWMSocket);
  procedure OnRead(Sender: TWMSocket);
  procedure OnClos(Sender: TWMSocket);
  procedure Prepare;
  protected
  procedure ParseUrl;
  public
  procedure Get; overload;
  procedure Get(_Url: string); overload;
  property Url: string read fUrl write fUrl;
  property HostPort: integer read fPort write fPort;
  property HostAddr: string read fAdr write fAdr;
  property UserName: string read fUsr write fUsr;
  property Password:  string read fPas write fPas;
  property Responce: integer read fCod write fCod;
  property Header: PStrList  read fHdr;
  property Content: PStrList read fCnt;
  property ContentLength: integer read fCnl;
  property ProxyAddr: string read fPAd write fPAd;
  property ProxyPort: integer read fPPr write fPPr;
  property OnClose: TOnEvent read fOnClos write fOnClos;
  end;

  function  NewKOLhttpControl: PKOLhttpControl;

implementation

uses UStr, UWrd;

const
  bin2b64:string='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';

function  NewKOLhttpControl: PKOLhttpControl;
begin
   New(Result, create);
   Result.fPort := 80;
   Result.fAdr  := '';
   Result.fUsr  := '';
   Result.fPas  := '';
   Result.fMth  := 'GET';
   Result.fHdr  := NewStrList;
   Result.fCnt  := NewStrList;
end;

function encode_line(const buf: string):string;
var
  offset: shortint;
  pos1,pos2: byte;
  i: byte;
  out: string;
begin
  setlength(out, length(buf) * 4 div 3 + 4);
  fillchar(out[1], length(buf) * 4 div 3 + 2, #0);
  offset:=2;
  pos1:=0;
  pos2:=1;
  out[pos2]:=#0;
while pos1 < length(buf) do begin
  if offset > 0 then begin
    out[pos2]:=char(ord(out[pos2]) or ((ord(buf[pos1 + 1]) and ($3f shl offset)) shr offset));
    offset:=offset-6;
    inc(pos2);
    out[pos2]:=#0;
    end
  else if offset < 0 then begin
    offset:=abs(offset);
    out[pos2]:=char(ord(out[pos2]) or ((ord(buf[pos1 + 1]) and ($3f shr offset)) shl offset));
    offset:=8-offset;
    inc(pos1);
    end
  else begin
    out[pos2]:=char(ord(out[pos2]) or ((ord(buf[pos1 + 1]) and $3f)));
    inc(pos2);
    inc(pos1);
    out[pos2]:=#0;
    offset:=2;
    end;
  end;
  if offset=2 then dec(pos2);
  for i:=1 to pos2 do
    out[i]:=bin2b64[ord(out[i])+1];
  while (pos2 and 3)<>0  do begin
    inc(pos2);
    out[pos2] := '=';
  end;
  encode_line := copy(out, 1, pos2);
end;

procedure TKOLhttpControl.OnDumm;
begin
end;

procedure TKOLhttpControl.OnConn;
begin
   fHdr.Clear;
   fCnt.Clear;
   fSoc.SendString(fMth + ' ' + fRef + ' HTTP/1.1'#13#10);
   fSoc.SendString('User-Agent: KOL-HTTP'#13#10);
   fSoc.SendString('Host: ' + fAdr + #13#10);
   if fUsr <> '' then begin
      fSoc.SendString('Authorization: Basic ' + encode_line(fUsr + ':' + fPas) + #13#10);
   end;
   fSoc.SendString(#13#10);
end;

procedure TKOLhttpControl.OnRead;
var s: string;
    c: integer;
begin
   while fSoc.Count > 0 do begin
      c := fSoc.Count;
      s := Wordn(fSoc.ReadLine(#10), #13, 1);
      if (c > 0) and (c = fSoc.Count) and (fCnl = c) then begin
         setlength(s, c);
         fSoc.ReadData(@s[1], c);
         Body := True;
      end;
      if pos('<', s) = 1 then Body := True;
      if Body then fCnt.Add(s)
              else fHdr.Add(s);
      if pos('HTTP/1.', s) = 1 then fCod := str2int(wordn(s, ' ', 2));
      if pos('Content-Length', s) = 1 then
         fCnl := str2int(wordn(s, ' ', 2));
   end;
   if Assigned(fOnClos) then fOnClos(@self);
end;

procedure TKOLhttpControl.OnClos;
begin
   if Assigned(fOnClos) then fOnClos(@self);
end;

procedure TKOLhttpControl.ParseUrl;
var s,
    r: string;
begin
   s := Url;
   if pos('HTTP://', UpSt(s)) = 1 then begin
      s := copy(s, 8, length(s) - 7);
   end;
   r := wordn(s, '@', 1);
   if r <> s then begin
      fUsr := wordn(r, ':', 1);
      fPas := wordn(r, ':', 2);
      s := wordn(s, '@', 2);
   end;
   r := wordn(s, ':', 2);
   if r <> '' then begin
      fPort := str2int(r);
      s := wordn(s, ':', 1);
   end;
   r := wordn(s, '/', 1);
   fAdr := r;
   if fAdr = '' then fAdr := s;
   fRef := copy(s, length(fAdr) + 1, length(s) - length(fAdr));
   if fRef = '' then fRef := '/';
end;

procedure TKOLhttpControl.Prepare;
begin
   Body := False;
   fSoc := NewAsyncSocket;
   ParseUrl;
   fSoc.PortNumber := fPort;
   fSoc.IPAddress  := fAdr;
   if fPAd <> '' then begin
      fSoc.IPAddress  := fPAd;
      fSoc.PortNumber := fPPr;
      fRef := 'http://' + fAdr + fRef;
   end;
   fSoc.OnConnect  := OnConn;
   fSoc.OnRead     := OnRead;
   fSoc.OnError    := OnDumm;
   fSoc.OnClose    := OnClos;
end;

procedure TKOLhttpControl.Get;
begin
   Prepare;
   fMth := 'GET';
   fSoc.DoConnect;
end;

procedure TKOLhttpControl.Get(_Url: string);
begin
   Url := _Url;
   Get;
end;

end.
alex0097 вне форума Ответить с цитированием
Старый 02.10.2017, 22:31   #6
Alex11223
Старожил
 
Аватар для Alex11223
 
Регистрация: 12.01.2011
Сообщений: 19,500
По умолчанию

Ну она ж не возвращает ничего. Видимо результат надо забирать в другом месте.
Смотрите что еще в классе есть.
Ушел с форума, https://www.programmersforum.rocks, alex.pantec@gmail.com, https://github.com/AlexP11223
ЛС отключены Аларом.
Alex11223 вне форума Ответить с цитированием
Старый 03.10.2017, 10:18   #7
Serge_Bliznykov
Старожил
 
Регистрация: 09.01.2008
Сообщений: 26,229
По умолчанию

Цитата:
Сообщение от Alex11223 Посмотреть сообщение
Ну она ж не возвращает ничего. Видимо результат надо забирать в другом месте.
точно.
и, судя по коду, результат нужно забирать в переменной(property) Content:

Цитата:
Код:
property Content: PStrList read fCnt;
Serge_Bliznykov вне форума Ответить с цитированием
Ответ


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



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Digest HTTP Auth или Basic HTTP Auth , оба SSL - есть разница? rlib Безопасность, Шифрование 2 14.10.2015 00:23
http server,http сервер, проблемы с post реализация на java snajper_ro Общие вопросы по Java, Java SE, Kotlin 1 23.10.2011 14:25
Http Proxy - как написать к браузеру http-прокси? SergeiGuk Общие вопросы .NET 0 21.05.2010 17:37