Solved

HTTP Get Problem

Posted on 2004-09-04
4
689 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now