Forum > Networking and Web Programming

GetURLText

(1/5) > >>

VTwin:
For a user to check for updates I have been using a very simple method, where a text file containing the current version (e.g., '3.21.0') is checked against the user's version.

I have been using a function GetURLText posted by trev, for quite a while, but it seems to no longer work. A search for GetURLText does not come up with a hit.

What is the best way to download a simple text file from a url?

KodeZwerg:
For what OS with what needs (plain old http or newer https) (username password needed?)

VTwin:
Thanks KodeZwerg,

I need something for macOS, Windows, and Linux, as in my profile.

I just want to download a text file, plain old http, no password.

Edit: Actually the site is https.
Something seems to have changed in the past few months.

KodeZwerg:
I am unsure about target platforms, please try for yourself.
(OPM -> Synapse -> Install)
Start a new project and try that:
(add to project requirement lazSynapse)

--- 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";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes , SysUtils , Forms , Controls , Graphics , Dialogs , StdCtrls ,  HTTPSend; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Memo1: TMemo;    procedure Button1Click(Sender: TObject);  strict private  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } function GetURLText(const AURL: string; out AText: string): Boolean;begin  AText := '';  Result := False;  with THTTPSend.Create do  begin    if HTTPMethod('GET', AURL) then    try      if Document.Size > 0 then      begin        Document.Position := 0;        SetLength(AText, Document.Size);        Document.ReadBuffer(Pointer(AText)^, Document.Size);        Result := AText <> '';      end;    except      Application.MessageBox('Unknown','Error', 0);    end;    Free;  end;end; procedure TForm1.Button1Click(Sender: TObject);var  s: string;begin  if GetURLText('http://your url with filename', s) then    Memo1.Lines.Add(s)    else    Memo1.Lines.Add('Error');end; end.

dsiders:

--- Quote from: VTwin on March 06, 2023, 12:58:18 am ---Thanks KodeZwerg,

I need something for macOS, Windows, and Linux, as in my profile.

I just want to download a text file, plain old http, no password.

Edit: Actually the site is https.
Something seems to have changed in the past few months.

--- End quote ---

You can use the TFPHttpClient class in the fphttpclient unit. It's cross-platform. Supports SSL when you use the appropriate optional units. Call the Get method, or SimpleGet to ignore protocol errors/exceptions.


--- 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";}};} ---AString := TFPHTTPClient.SimpleGet(AUrl);
See: https://wiki.freepascal.org/fphttpclient

Navigation

[0] Message Index

[#] Next page

Go to full version