José Carvalho
José Carvalho

Reputation: 11

HTTPReqResp OnBeforePost change in Delphi 10.3

I have an event code that previously used the Data parameter, but in Delphi 10.3 this parameter was replaced.

Before Delphi 10.3:

procedure THTTPEvents.HTTPReqResp1BeforePost(const HTTPReqResp: THTTPReqResp; Data: Pointer);
begin
  // set the certificate to use for the SSL connection
  if not InternetSetOption(Data, INTERNET_OPTION_CLIENT_CERT_CONTEXT, PCertContext, Sizeof(CERTCONTEXT)*5)
    then Raise Exception.Create('Problema no certificado!');
end;

In this code, I use InternetSetOption(), how should I proceed now in Delphi 10.3? How to get the Data parameter?

procedure THTTPEvents.HTTPReqResp1BeforePost(const HTTPReqResp: THTTPReqResp; Data: Pointer);
var
  Store        : IStore;
  Cert         : ICertificate2;
  CertContext  : ICertContext;
  PCertContext : PCCERT_CONTEXT;
begin
  try
    if not FileExists(HTTPEvents.PFXFile) then
      Raise Exception.Create('Ficheiro de certificado não encontrado!');

    HttpReqResp.ConnectTimeout := 12000;
    HttpReqResp.ReceiveTimeout := 12000;
    HttpReqResp.SendTimeout := 12000;

    // create Certificate store object
    Store := CoStore.Create;
    Cert := CoCertificate.Create;
    Cert.Load(HTTPEvents.PFXFile, HTTPEvents.PFXPass, CAPICOM_KEY_STORAGE_DEFAULT, CAPICOM_CURRENT_USER_KEY);
    CertContext := Cert as ICertContext;
    CertContext.Get_CertContext(Integer(PCertContext));

    // set the certificate to use for the SSL connection
    if not InternetSetOption(Data, INTERNET_OPTION_CLIENT_CERT_CONTEXT, PCertContext, Sizeof(CERTCONTEXT)*5)
      then Raise Exception.Create('Problema no certificado!');
    CertContext.FreeContext(Integer(PCertContext));
  except
    ON E:Exception DO ShowMessage(E.Message);
  end;
end;

All the code in BeforePost Event. This piece of code not work in delphi 10.3, because the parameter "Data". This problem drive me crazy, if someone help i appreciate.

Upvotes: 1

Views: 1656

Answers (0)

Related Questions