Thema: Delphi REST Request Fehler

Einzelnen Beitrag anzeigen

TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
2.836 Beiträge
 
Delphi 10.2 Tokyo Enterprise
 
#16

AW: REST Request Fehler

  Alt 11. Jan 2021, 16:04
Meine obige Idee noch schnell skizziert. Wie geschrieben die System.Net.HttpClient.Win Unit kopieren und dem eigenen Projekt hinzufügen, um Änderungen vornehmen zu können:

Delphi-Quellcode:
procedure HTTPCallback(hInternet: HINTERNET; dwContext: Pointer; dwInternetStatus: DWORD;
    lpvStatusInformation: Pointer; dwStatusInformationLength: DWORD); stdcall;
var
// LRequest: TWinHTTPRequest;
  StatusFlags: DWORD;
  Flag: DWORD;

  function FlagToString(Flag: DWORD): string;
  begin
    case Flag of
       WINHTTP_CALLBACK_STATUS_FLAG_CERT_REV_FAILED : Result := 'CERT_REV_FAILED';
       WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CERT : Result := 'INVALID_CERT';
       WINHTTP_CALLBACK_STATUS_FLAG_CERT_REVOKED : Result := 'CERT_REVOKED';
       WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CA : Result := 'INVALID_CA';
       WINHTTP_CALLBACK_STATUS_FLAG_CERT_CN_INVALID : Result := 'CERT_CN_INVALID';
       WINHTTP_CALLBACK_STATUS_FLAG_CERT_DATE_INVALID : Result := 'CERT_DATE_INVALID';
       WINHTTP_CALLBACK_STATUS_FLAG_CERT_WRONG_USAGE : Result := 'CERT_WRONG_USAGE';
       WINHTTP_CALLBACK_STATUS_FLAG_SECURITY_CHANNEL_ERROR : Result := 'SECURITY_CHANNEL_ERROR';
    end;
  end;

  procedure CheckFlags(Value, Flag: DWORD);
  begin
    if (Value and Flag) = Flag then
      Writeln(Flag.ToHexString, Format(' %s is in lpvStatusInformation', [FlagToString(Flag)]));
  end;

begin
  AllocConsole;
  case dwInternetStatus of
    WINHTTP_CALLBACK_STATUS_SECURE_FAILURE:
    begin
// LRequest := TWinHTTPRequest(dwContext);
      StatusFlags := PDWORD(lpvStatusInformation)^;

      CheckFlags(StatusFlags, WINHTTP_CALLBACK_STATUS_FLAG_CERT_REV_FAILED);
      CheckFlags(StatusFlags, WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CERT);
      CheckFlags(StatusFlags, WINHTTP_CALLBACK_STATUS_FLAG_CERT_REVOKED);
      CheckFlags(StatusFlags, WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CA);
      CheckFlags(StatusFlags, WINHTTP_CALLBACK_STATUS_FLAG_CERT_CN_INVALID);
      CheckFlags(StatusFlags, WINHTTP_CALLBACK_STATUS_FLAG_CERT_DATE_INVALID);
      CheckFlags(StatusFlags, WINHTTP_CALLBACK_STATUS_FLAG_CERT_WRONG_USAGE);
      CheckFlags(StatusFlags, WINHTTP_CALLBACK_STATUS_FLAG_SECURITY_CHANNEL_ERROR);
    end;
  end;
end;

constructor TWinHTTPClient.Create;
begin
  inherited Initializer;

  FWinCertList := TList<PCCERT_CONTEXT>.Create;
  FCertificateList := TList<TCertificate>.Create;

  GLib.LockHandleGC;
  FWSession := WinHttpOpen('', WINHTTP_ACCESS_TYPE_NO_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
  if FWSession = nil then
    raise ENetHTTPClientException.CreateRes(@SNetHttpClientHandleError);

  WinHttpSetStatusCallback(FWSession, HTTPCallback, WINHTTP_CALLBACK_STATUS_SECURE_FAILURE, 0); // das ist neu!
end;
Statt einer Console kann natürlich ein beliebiger anderer Logging-Mechanismus verwendet werden.
  Mit Zitat antworten Zitat