In unit_gethtml I see some issues:
- in the uses clause
ssl_openssl is missing, which renders it a bit useless, since everybody uses https
- the uses clause otherwise contains a lot of
futile unused units, which slows down compile times.
- Why do you write
begin
page.LoadFromStream(http.Document);
for i:=0 to page.Count-1 do
risultato:=risultato + (page[i]);
end;
Instead of:
begin
page.LoadFromStream(http.Document);
risultato:=Page.Text; // <-------------
end;
That is less error prone.
In general it would be best to replace that function with synapse' standard function:
I would write it like this:
unit unit_gethtml;
{$mode objfpc}
interface
uses httpsend, ssl_openssl;
function RecuperaHtml(const Url: string): string;
implementation
uses classes;
function RecuperaHtml(const Url: string): string;
var
L:TStrings;
begin
Result :='';
try
L := TStringlist.Create;
if HttpGetText(Url,L) then Result := L.Text;
finally
L.Free;
end;
end;
end.
Advantages:
- less error prone
- allows redirects!
- supports https