Recent

Author Topic: [SOLVED] How to read data from an URL address  (Read 8988 times)

sorinr

  • New Member
  • *
  • Posts: 19
[SOLVED] How to read data from an URL address
« on: February 13, 2011, 12:02:36 pm »
Hi all,

Can anybody give me some idea on how to read a value returned by a web page?

So, let me explain my problem:

1. I need to read a value (that in fact is the exchange rate of a currency at a certain date) from a web page like "www.infovalutar.ro/bnr/YYYY/MM/DD/EUR". The web page returns the exchane rate of the currency you select, in my case EUR or it can be USD, CAD whatever.
2. I am using Lazarus 0.9.28 on a win32 machine and i have the Inet package installed.

Thank you in advance for your help
« Last Edit: February 28, 2011, 04:40:23 pm by sorinr »

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: How to read data from an URL address
« Reply #1 on: February 13, 2011, 01:24:45 pm »
If you have lNET, open visual example of HTTP. There is "how to" read http data from given link. Just put your link.
Or, download and use synapse:
1. Add httpsend to uses section
2. Call:
Code: Pascal  [Select][+][-]
  1. uses httpsend;
  2.  
  3. procedure Button1Click(Sender: TObject);
  4.   var
  5.     s: TMemoryStream;
  6. begin
  7.   s := TMemoryStream.Create;
  8.   try
  9.     HttpGetText('http://www.infovalutar.ro/bnr/YYYY/MM/DD/EUR', s);
  10.     s.Position := 0;
  11.     Memo1.Lines.LoadFromStream(s);
  12.   finally
  13.     s.Free;
  14.   end;
  15. end;
  16.  

Sorry, above code wrong format your link.
« Last Edit: February 13, 2011, 01:26:56 pm by Dibo »

sorinr

  • New Member
  • *
  • Posts: 19
Re: How to read data from an URL address
« Reply #2 on: February 13, 2011, 01:44:12 pm »
Hi Dibo,

Thanks for your reply. I've seen it just before to post the solution I've found using HTTPsend instead of Inet. Here is the code I have used:

procedure TForm1.FormActivate(Sender: TObject);
var
response: Tstringlist;
HTTP: THTTPSend;
result: boolean;
begin
  Response := TStringList.Create;
  HTTP := THTTPSend.Create;
  try
    Result := HTTP.HTTPMethod('GET', 'http://www.infovalutar.ro/bnr/2011/02/13/usd/');
    if Result then
      Response.LoadFromStream(HTTP.Document);
      edit1.Text:=Response[0];
  finally
    HTTP.Free;
  end;

end;

Thanks to all. PROBLEM SOLVED! :D                      
« Last Edit: February 13, 2011, 09:38:18 pm by sorinr »

 

TinyPortal © 2005-2018