I’m using Arch Linux with Lazarus 3.0rc2 and fpc 3.2.2-9. For the missing http.Free, I forgot to add it to my post. However it still didn’t work.
Did you try project I attached?
I did, and it worked. But not in my project.
I’m using Arch Linux with Lazarus 3.0rc2 and fpc 3.2.2-9. For the missing http.Free, I forgot to add it to my post. However it still didn’t work.
Since the resulting number of characters that you do receive seem to be around 250 ... are you perhaps using shortstring ?
Full compilable example please (including used compiler/build flags) . Anything else is just a guessing game.
Shortstring... you made me realized that I need the {$H+}. That's why the result is that short.
Firstly I tried dseligo's code, then just run TFPHTTPClient.Get(URL). I tried to assign the result to a variable and writeln() it, and yet the download result still that short.
Indeed I did not used any compiler/build flag else than {$mode objfpc} in my file (which is -Mobjfpc on command-line) for now (I don't use Lazarus). Here is my code (not fixed):
unit resoures;
{$mode objfpc}
Interface
function downloadItem(const URL: ansistring): string;
function downloadItem(const URL: ansistring, outPath: ansistring): boolean;
function getReleases: TStringArray;
Implementation
function downloadItem(const URL: shortstring): shortstring;
var
http: TFPHTTPClient;
begin
http := TFPHTTPClient.Create(nil);
try
result := http.Get(URL);
finally
http.Free;
end;
end;
function downloadItem(const URL: ansistring; outPath: ansistring): boolean;
var
fs: TFileStream;
http: TFPHTTPClient;
begin
http := TFPHTTPClient.Create(nil);
FS := TFileStream.Create(outPath, fmCreate or fmOpenWrite);
try
http.Get(URL, FS);
finally
fs.Free;
http.Free;
result := true;
end;
end;
function getReleases: TStringArray;
var
URL: string;
content: string;
begin
if usesNightly = true then
URL := 'https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/main'
else
URL := 'https://cdn.nickchan.lol/palera1n/c-rewrite/releases/';
content := downloadItem(URL);
writeln(content);
// unimplemented html parse
end;
end.
Currently my program just calls getReleases at first.
The problem is fixed for now, thanks everyone for trying to help me out! I will need to learn more...