Solved

HTTP Get Problem

Posted on 2004-09-04
4
691 Views
Last Modified: 2012-05-05
Dear Sir

I di small application to read the source from a web page

the code:

procedure TForm1.Timer1Timer(Sender: TObject);
var
  ii, jj:integer;
  s1, res :STRING;
begin
timer1.Enabled:= false;

         s1:= idhttp1.Get('http://www.omarfayyad.com/md/index.php');

         ii := pos('startofm',s1)+10;
         jj := pos('endofm',s1)-27;
         res := Copy(s1,ii, jj-ii);
         if (AnsiCompareText(oldres, res)<>0) then
           begin
             oldres:= res;
             memo.Clear;
             memo.Lines[0]:= res;
           end;
idhttp1.Disconnect;
timer1.Enabled:= true;
end;

it isworking fine, put after updating the web page, it reads the new contents.  the second try it reads the old ones. then it reds the new contents the some very old one ....... after 5 .. 7 tryes it starts working will and forgots any old contents.

so please advice where is the problem and from where it gets the old contents when the are changed.

thank you in advance

Eng. Omar Fayyad

0
Comment
Question by:omarmf
  • 3
4 Comments
 
LVL 2

Expert Comment

by:MrT-RSI
ID: 11981263
Are you using a proxy server ? Maybe the proxy is delevering you the old version.

Turn the use of a proxy of, or check your IE settings, or try a little 'tweak' by requesting your page with 'a' param, e.g.: .Get('.../index.php?param=123'); maybe this will force the proxy to reload the page.
0
 
LVL 1

Expert Comment

by:mgazza
ID: 12092778
y are you using a conponent? is it worth that overhead?

var
zero:cardinal=0;
procedure HTTPs(URL,Headers:PChar;var OutHeaders, OutDoc:string);

var
  RequestHandle,IOpenHandle : PHandle;
  DataWritten:cardinal;
  buffer:array[0..100] of char;
begin

  IOpenHandle:= InternetOpen('Mozilla/4.0 (compatible)', INTERNET_OPEN_TYPE_PRECONFIG , NIL, NIL, 0);

  // open the file
  RequestHandle:=InternetOpenUrl(iOpenHandle, URL, Headers, length(Headers),
                          INTERNET_FLAG_RAW_DATA or INTERNET_FLAG_SECURE,0);

  if RequestHandle<>nil then begin
   repeat
     if InternetReadFile(RequestHandle,@buffer[0],sizeof(buffer),DataWritten) then
        OutDoc:=OutDoc+copy(buffer,0,DataWritten) else break;
   until DataWritten=0;
   setlength(outheaders,512);
   repeat
    DataWritten:=length(outheaders);
     if HttpQueryInfoA(RequestHandle, HTTP_QUERY_RAW_HEADERS_CRLF, @outheaders[1],DataWritten,zero) then begin
      setlength(outheaders,datawritten);
      break;
     end
     else setlength(outheaders,datawritten*2);
    until datawritten=1024*5;

  end;

  InternetCloseHandle(requestHandle);
  InternetCloseHandle(IOpenHandle);
end;


procedure HTTP(URL,Headers:PChar;var OutHeaders, OutDoc:string);

var
  RequestHandle,IOpenHandle : PHandle;
  DataWritten:cardinal;
  buffer:array[0..100] of char;
begin

  IOpenHandle:= InternetOpen('Mozilla/4.0 (compatible)', INTERNET_OPEN_TYPE_PRECONFIG , NIL, NIL, 0);

  // open the file
  RequestHandle:=InternetOpenUrl(iOpenHandle, URL, Headers, length(Headers),
                          INTERNET_FLAG_RAW_DATA,0);

  if RequestHandle<>nil then begin
   repeat
     if InternetReadFile(RequestHandle,@buffer[0],sizeof(buffer),DataWritten) then
        OutDoc:=OutDoc+copy(buffer,0,DataWritten) else break;
   until DataWritten=0;
   setlength(outheaders,512);
   repeat
    DataWritten:=length(outheaders);
     if HttpQueryInfoA(RequestHandle, HTTP_QUERY_RAW_HEADERS_CRLF, @outheaders[1],DataWritten,zero) then begin
      setlength(outheaders,datawritten);
      break;
     end
     else setlength(outheaders,datawritten*2);
    until datawritten=1024*5;

  end;

  InternetCloseHandle(requestHandle);
  InternetCloseHandle(IOpenHandle);
end;
0
 
LVL 1

Expert Comment

by:mgazza
ID: 12092789
where headers is optional headers #13#10
procedure TForm1.Button1Click(Sender: TObject);
var
Head:Pchar;
d,h:string;
begin

https('https://www.omarfayyad.com/md/index.php',nil,h,d);
or
http('http://www.omarfayyad.com/md/index.php',nil,h,d);
respectfuly
showmessage(h+d)

end;

regards
0
 
LVL 1

Accepted Solution

by:
mgazza earned 250 total points
ID: 12123431
any comment would be useful
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question