Solved

HTTP Get Problem

Posted on 2004-09-04
4
694 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
[X]
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
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

705 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