Determining end of transmission

libdanz
libdanz used Ask the Experts™
on
Hie people I have the code and I wanted to know what function to use to determine whether the HTTP server has finished sending data. Currently I am using the code below but it doesnt take all the data from the HTTP server.



procedure TForm1.Button1Click(Sender: TObject);
var
  s:string;
  t:integer;
  P:PCHAR;
begin
   t:=0;
   memo1.Clear;
   TCPClient1.Close;
   TCPClient1.RemoteHost:='www.yahoo.com';
   TCPClient1.RemotePort:='80';
   TCPClient1.Active:=true;
   TCPClient1.Open;

   TcpClient1.Sendln('POST / HTTP/1.1');
   TcpClient1.Sendln('Host: www.zbc.co.zw');
   TcpClient1.Sendln('Accept: */*');
   TcpClient1.Sendln('From: frog@jmarshall.com');
   TcpClient1.Sendln('User-Agent: Mozilla/1.0');
   TcpClient1.Sendln('Content-Type: application/x-www-form-urlencoded');
   TcpClient1.Sendln('Content-Length: 32');
   TcpClient1.Sendln('Connection: close'+#10);
   TcpClient1.Sendln('home=Cosby&favorite+flavor=flies');
   TcpClient1.Sendln(#10);
   repeat
       s:=TCPClient1.Receiveln();
       memo1.Lines.Add(String(s));
       if(length(s)=0) then t:=t+1;
   until t=2;
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
var
 s:string;
 t:integer;
 P:PCHAR;
begin
  t:=0;
  memo1.Clear;
  TCPClient1.Close;
  TCPClient1.RemoteHost:='www.yahoo.com';
  TCPClient1.RemotePort:='80';
  TCPClient1.Active:=true;
  TCPClient1.Open;

  TcpClient1.Sendln('POST / HTTP/1.1');
  TcpClient1.Sendln('Host: www.zbc.co.zw');
  TcpClient1.Sendln('Accept: */*');
  TcpClient1.Sendln('From: frog@jmarshall.com');
  TcpClient1.Sendln('User-Agent: Mozilla/1.0');
  TcpClient1.Sendln('Content-Type: application/x-www-form-urlencoded');
  TcpClient1.Sendln('Content-Length: 32');
  TcpClient1.Sendln('Connection: close'+#10);
  TcpClient1.Sendln('home=Cosby&favorite+flavor=flies');
  TcpClient1.Sendln(#10);
  while (true) do
  begin
      if (NOT TCPClient1.WaitForData(5000)) then
        break;
      s:=TCPClient1.Receiveln(#10);
      memo1.Lines.Add(String(s));
      if(length(s)=0) then t:=t+1;
  end;
  TcpClient1.Close;
end;

Author

Commented:
Thank you very much, do have an algorithm to pass the returned data from the HTTP server..

I want to seperate the headers and the data, and also there are some characters that appear after the headers, that I dont understand, and a Zero at the bottom of the data...what do they mean.

Commented:
the header comes 2 \r\n's before the data
so:

[headers]
\r\n
\r\n
[data]

remove the last 2 lines of the data

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial