尝试在Delphi中使用Indy 10.6.2访问HTTP服务器时出现403错误

时间:2018-10-25 13:05:24

标签: delphi ssl indy

我尝试与一种服务进行通信,但始终出现403错误。当我尝试SoapUI时,传递查询没有问题。我要去哪里错了?

我使用openssl-1.0.1c-x64_86-win64。

  var
    urlADR, resTXT, resp_CMD, json : string;
    IdHTTP : TIdhttp;
    IdSSLIO  : TIdSSLIOHandlerSocketOpenSSL;
    JsonToSend : TStringStream;
    respCode : Integer;

begin

  urlADR := 'https://mvr.bg/webservices/api/Document/CheckDocument';
  Json := '{"documentKindCode":"6729","documentNumber":"123456789","birthsday":"01.01.1977"}';

  JsonToSend := TStringStream.Create(Utf8Encode(Json));       // D2007 and earlier

  IdSSLIO := TIdSSLIOHandlerSocketOpenSSL.Create(self);
  IdHTTP  := TIdhttp.Create(self);
  try
    IdSSLIO.Host := 'mvr.bg';
    IdSSLIO.SSLOptions.SSLVersions := [sslvTLSv1_2];
    with IdHTTP do begin
      IOHandler := IdSSLIO;
      Request.ContentType    := 'application/json';
      Request.AcceptEncoding := 'gzip,deflate';
      Request.Connection     := 'Keep-Alive';
      Request.Host           := 'mvr.bg';
      Request.CharSet        := 'utf-8';

      resp_CMD := POST( urlADR, JsonToSend );

    end;

    ShowMessage(resp_CMD);

  finally
    IdSSLIO.Free;
    IdHTTP.Free;
    JsonToSend.Free;
  end;

0 个答案:

没有答案