Forum > Networking and Web Programming

[SOLVED] TFPHTTPClient.Get(URL) / SimpleGet(URL) do not get the full HTML

<< < (2/2)

lebao3105:

--- Quote from: dseligo on December 01, 2023, 09:14:00 pm ---
--- Quote from: lebao3105 on December 01, 2023, 05:24:55 pm ---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.

--- End quote ---

Did you try project I attached?

--- End quote ---

I did, and it worked. But not in my project.


--- Quote from: TRon on December 01, 2023, 06:01:42 pm ---
--- Quote from: lebao3105 on December 01, 2023, 05:24:55 pm ---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.

--- End quote ---
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.

--- End quote ---

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):


--- 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 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 parseend; 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...

dseligo:

--- Quote from: lebao3105 on December 02, 2023, 05:24:06 am ---The problem is fixed for now, thanks everyone for trying to help me out! I will need to learn more...

--- End quote ---

If you use {$mode objfpc}, then add {$H+} to it so that it looks like that:

--- 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";}};} ---{$mode objfpc}{$H+}
In mode Delphi Ansistrings are turned on by default.

Also change Shortstring type to String in your program.

TRon:

--- Quote from: lebao3105 on December 02, 2023, 05:24:06 am ---Shortstring... you made me realized that I need the {$H+}. That's why the result is that short.

--- End quote ---
Thank you for reporting back and good to hear that you got that sorted out.

$H+ is a small (as in number of characters) but very important directive fir these cases. dseligo's advise to always define it when using mode objfpc is solid (for now, until/once using unicode rtl which is a new upcoming feature and for which default string type settings might change and/or be different).

Thaddy:

--- Quote from: dseligo on December 02, 2023, 10:38:26 am ---Also change Shortstring type to String in your program.

--- End quote ---
Imnsho opinion it is the other way around, specify your string type exactly.... >:D >:D >:D >:D
That way you do not mix up all the alternative string types available that modern pascal provides. Just string is horrid. Especially for beginners that do not know about modes.
BAD advice.                               

Navigation

[0] Message Index

[*] Previous page

Go to full version