THTTPsend lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- DanishMale · 2025-08-01 11:33 Hi I am a total newbie to Synapse and HTTPsend and don't seem to be able to find the correct settings I have written this code and it returns 500 - Internal server error Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function GetHTTP(webaddress: String; headerdata: TStringList = nil): String;const  WEB_USERAGENT : Array of String = (  'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36',  'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0',  'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0'  );begin  WEBdata := THTTPsend.Create;  try    WEBdata.Clear;    WEBdata.Protocol:='1.1';  WEBdata.UserAgent := WEB_USERAGENT[RandomBetween(0, Length(WEB_USERAGENT)-1)];    WEBdata.KeepAlive := True;    WEBdata.MimeType := headerdata[0];    headerdata.Delete(0);    WEBdata.Headers.AddStrings(headerdata);    if not WEBdata.HTTPMethod('GET', webaddress) then    begin      raise exception.create(IntToStr(WEBdata.ResultCode) + ' - ' + GetHTTPerrorText(WEBdata.ResultCode));    end;    Result := WEBdata.Document.ReadAnsiString;  except    on E: Exception do    begin      Result := 'ERROR - '+E.Message+LineEnding+LineEnding+IntToStr(WEBdata.ResultCode) +              ' - ' + GetHTTPerrorText(WEBdata.ResultCode) +              LineEnding+LineEnding+WEBdata.Headers.Text;    end;  end;  headerdata := nil;  WEBdata.Free;end;  and is called with this code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button2Click(Sender: TObject);begin  Memo1.Clear;  HeaderList := TStringList.Create;  HeaderList.Clear;  HeaderList.Add('text/html,a pplication/xhtml+xml,application/xml;q=0.9,*/*;q=0.8');  HeaderList.Add('Accept: */*; q=0.01');  HeaderList.Add('Accept- Language: da,en-US;q=0.7,en;q=0.3');  HeaderList.Add('Accept-Encoding: gzip, deflate, br, zstd');  Memo1.Lines.Add(GetHTTP('https://www.tnt.fr', HeaderList));end;  I have added laz_synapse to the project and upgraded to ssl_openssl3 in synapse also downloaded the latest DLL's in x64. I wonder what I can't see or overlooking.......... Any help is really appreciated ---------------------------------------------------------------------- rvk · 2025-08-01 11:38 First line in your header string list is Content-Type: text/html You take that and put it in thhtpsend.mimetype. The ENTIRE line. That's incorrect. You need to only take the value after : and out it in mimetype. ---------------------------------------------------------------------- DanishMale · 2025-08-01 11:45 Quote from: rvk on August 01, 2025, 01:38:52 pmFirst line in your header string list is Content-Type: text/html You take that and put it in thhtpsend.mimetype. The ENTIRE line. That's incorrect. You need to only take the value after : and out it in mimetype. Corrected , however, still same error .... ---------------------------------------------------------------------- rvk · 2025-08-01 12:49 First I'm not entirely sure why you want to set a MimeType (Content- Type) for a GET. Second... you do get an error 500 when openssl isn't initialized properly. Did you add ssl_openssl or ssl_openssl3 to your uses clause? And put the correct openssl dll's in the exe directory. Third... I'm not sure you can use THTTPSend.Document.ReadAnsiString to get the data. It is a TMemoryStream so TStream.ReadAnsiString should work but for me it crapped out with a read stream exception. You CAN'T use TStream.ReadAnsiString because that expects a length at the beginning of the stream (see the ReadBuffer (TheSize ) at the beginning). You can use this snippet to put the content of the memorystream to a string; Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function MemoryStreamToString(M: TMemoryStream): ansistring;begin  SetString(Result, PAnsiChar(M.Memory), M.Size);end; ---------------------------------------------------------------------- Thaddy · 2025-08-01 13:39 I would not use Synapse for that anymore, but TFPHttpClient: better maintained, modern and standard. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode objfpc} uses  Sysutils, classes, fphttpclient, opensslsockets;  const  WEB_USERAGENT : Array of String = (  'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36',  'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0',  'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0'  );  var  Client: TFPHttpClient;  Page:TStrings;begin  Client := TFPHttpClient.Create(nil);  Page := TStringlist.Create;  try    Randomize;    Client.AddHeader('User- Agent', WEB_USERAGENT[Random(High(WEB_USERAGENT)+1)]);    Client.AddHeader('Content-Type','text/html,application/xhtml+xml,appli cation/xml;q=0.9,*/*;q=0.8');    Client.AddHeader('Accept-Encoding', 'gzip, deflate, br, zstd');    Client.AddHeader('Accept-Language',' da,en-US;q=0.7,en;q=0.3');    Client.AddHeader('Accept', '*/*; q=0.01');    Client.AllowRedirect := true;    try      Client.Get('https://www.tnt.fr',Page);      Writeln(Page.Text);     // or simply writeln(Client.Get('https://www.tnt.fr',Page)) and save you a stringlist    except      on E:Exception do        writeln(e.message);    end;  finally    Page.Free;    Client.Free;  end;end.