Forum > Networking and Web Programming
[SOLVED] How to read data from an URL address
(1/1)
sorinr:
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
Dibo:
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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses httpsend; procedure Button1Click(Sender: TObject); var s: TMemoryStream;begin s := TMemoryStream.Create; try HttpGetText('http://www.infovalutar.ro/bnr/YYYY/MM/DD/EUR', s); s.Position := 0; Memo1.Lines.LoadFromStream(s); finally s.Free; end;end;
Sorry, above code wrong format your link.
sorinr:
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
Navigation
[0] Message Index