Estefanie 0 Posted September 21, 2020 Hello I am getting this error when doing a GET in a url. "404 Connection aborted on request" or this mistake access violation in delphi xe2 This is my code in the button var data: String; HttpClient: TSslHttpCli; xmlDoc: TXMLDocument; dataStream: TMemoryStream; begin mResult.Lines.Clear; xmlDoc := TXMLDocument.Create(Self); HttpClient := TSslHttpCli.Create(nil); HttpClient.ContentTypePost := 'text/xml'; HttpClient.URL:= 'https://www.poemist.com/api/v1/randompoems'; HttpClient.RcvdStream := TStringStream.Create(''); try try ShowMessage(IntToStr(HttpClient.StatusCode)); //HttpClient.GetASync; HttpClient.Get; ShowMessage('-3-1-'); { SslHttpCli.SendStream := dataStream; SslHttpCli.SendStream.Write(Data[1], Length(Data)) ; SslHttpCli.SendStream.Seek(0,0); mResult.Lines.LoadFromStream(dataStream); } // xmlDoc.LoadFromStream(HttpClient.RcvdStream); // xmlDoc.Active := True; dataStream.LoadFromStream(SslHttpCli.RcvdStream); mResult.Lines.LoadFromStream(dataStream); // mResult.Lines.LoadFromStream(HttpClient.RcvdStream); Except raise; end; finally HttpClient.Free; xmlDoc.Free; end; Share this post Link to post
Angus Robertson 574 Posted September 22, 2020 You are trying to use SSL/TLS without using the proper components, you need to assign a TSslContext component to the SslContext property of HttpClient and initialise it correctly, see the PrepareConnection function in the OverbyteIcsHttpsTst1.pas HTTPS sample, although that uses lots of options you don;t actually need. Angus Share this post Link to post
Fr0sT.Brutal 900 Posted September 22, 2020 6 minutes ago, Angus Robertson said: you need to assign a TSslContext component to the SslContext property of HttpClient and initialise it correctly Side note: maybe add some friendliness? Clear error message that will explain what's wrong or even default init that will just work without any additional hassle. Share this post Link to post
Angus Robertson 574 Posted September 22, 2020 He is using an old component, the latest TSslHttpRest does all this automatically. But long experience in this forum shows people that start using the wrong component would rather continue trying to use it, than change to something better and easier, this comes up again and again and is really down to not enough ICS documentation, which costs money to write, which no-one wants to spend. Angus Share this post Link to post
Lars Fosdal 1792 Posted September 22, 2020 I guess injecting a deprecated statement for the old class could be an option - or is that too brutal. Share this post Link to post
Angus Robertson 574 Posted September 22, 2020 The old class is not deprecated, the new component descends from the old one so is 100% compatible, but includes many optional addons such as SSL to make it easier to use. Angus 1 Share this post Link to post