Jump to content
Estefanie

TSslHttpCli Access violation at address or 404 error

Recommended Posts

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;

 

 

image.thumb.png.29812cfeb0c2525a1d9ee589f97d4638.png

Share this post


Link to post

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

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

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

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

 

  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×