Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

HTTP Get Problem

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi exception 7 68
FMX enumerated colours 2 115
how to center only a line in richedit? 4 61
can i put an image from resource into image tag ? 6 26
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

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