You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Ararat Synapse实现TLS1.2 HTTPS POST失败(CIS已成功)求助

问题:使用Ararat Synapse发起TLS 1.2 POST请求获取Bearer Token失败(Clever Internet Suite可成功)

我需要发起TLS 1.2的HTTP POST请求,获取JSON格式的Bearer Token,后续所有POST/GET请求都要将该Token添加至请求头中。目前已通过Clever Internet Suite成功实现此功能,但使用2025年2月下载的Ararat Synapse时请求失败。


两个项目共用的常量

const 
c_username = 'AUSERNAME'; 
c_password = 'APASSWORD'; 
c_client_id= 'ACLIENTID'; 
c_url      = 'https://www.server.com/vendd/token';

使用Clever Internet Suite的成功测试代码

procedure TForm2.ButtonA2Click(Sender: TObject);
var  AHTTP:TclHttp;
     AReq:TclHttpRequest;     AItem:TclHttpRequestItem;
     s:string;   aurl,FErrorDescr:string;
     ResObj,HelpObj: TJsonObject;  FTokenLimit:TDateTime;
begin
  try
    try
      AHTTP:=TclHttp.Create(nil);     Areq:= TclHttpRequest.create(nil);
      with AHTTP do begin
        HttpVersion:=hvHttp1_1;
        TLSFlags:=[tfUseTLS12];
        UseTLS:=ctAutomatic;
      end;
      with Areq do begin
        AITem:=AReq.Items.Add(TclFormFieldRequestItem);
          with TclFormFieldRequestItem(AITem) do begin
            FieldName:='grant_type'; FieldValue:='password';
          end;
        AITem:=AReq.Items.Add(TclFormFieldRequestItem);
          with TclFormFieldRequestItem(AITem) do begin
            FieldName:='username'; FieldValue:=c_username;
          end;
        AITem:=AReq.Items.Add(TclFormFieldRequestItem);
          with TclFormFieldRequestItem(AITem) do begin
            FieldName:='password'; FieldValue:=c_password;
          end;
        AITem:=AReq.Items.Add(TclFormFieldRequestItem);
          with TclFormFieldRequestItem(AITem) do begin
            FieldName:='client_id'; FieldValue:=c_client_id;
          end;
      end;
      aurl:=c_url;
      s:=AHTTP.Post(aurl,Areq);
      Memo1.Lines.add(s);
      ResObj:=TJsonObject.Parse(s) as TJsonObject;
      if AHTTP.StatusCode = 200 then begin    
      end else begin
      end;
    except
      on E:Exception do begin
        ShowMessage(E.Message);
      end;
    end;
  finally
    AHTTP.Free;  AReq.Free;
  end;
end;

使用Ararat Synapse的失败测试代码

环境说明与错误信息

应用程序目录下已放置以下32位DLL:

  • libssl-1_1.dll:版本1.1.1.23(1.1.1w),日期2023年9月11日
  • libcrypto-1_1.dll:版本1.1.1.23(1.1.1w),日期2023年9月11日
  • libssl-3.dll:版本3.4.1.0,日期2025年2月11日
  • libcrypto-3.dll:版本3.4.1.0,日期2025年2月11日

请求现象:MyHttpPostURL返回true(无报错),但服务器返回权限拒绝:

访问被拒绝
您无权访问此服务器上的“http://www-server.com/vendd/token”。

参考编号 #18.777ecdd4.1739735221.243974bb
https://errors.edgesuite.net/18.777ecdd4.1739735221.243974bb

测试代码

uses 
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, 
Vcl.Controls, Vcl.Forms, Vcl.Dialogs,System.strutils,Vcl.StdCtrls,Vcl.Graphics,
HttpSend,blcksock, synautil, synaip, synacode, synsock,
ssl_openssl11, ssl_openssl11_lib 
//也可替换为 ssl_openssl3_lib, ssl_openssl3 

function MyHttpPostURL(const URL, URLData: string; const Data: TStream): Boolean;
{ MyHttpPostURL是Synapse库HttpPostUrl的完整拷贝,仅新增以下代码:
  HTTP.protocol:='1.1';
  HTTP.Sock.SSL.SSLType:=LT_TLSv1_2;
  HTTP.UserAgent:='Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0';
  WriteStrToStream为Synapse原生代码
}
var
  HTTP: THTTPSend;
begin
  HTTP := THTTPSend.Create;
  HTTP.protocol:='1.1';
  HTTP.Sock.SSL.SSLType:=LT_TLSv1_2;
  HTTP.UserAgent:='Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0';
  try
    WriteStrToStream(HTTP.Document, URLData);
    HTTP.MimeType := 'application/x-www-form-urlencoded';
    Result := HTTP.HTTPMethod('POST', URL);
    if Result then
      Data.CopyFrom(HTTP.Document, 0);
  finally
    HTTP.Free;
  end;
end;

procedure TForm2.SB_Auth2Click(Sender: TObject);
var MS:TMemoryStream;    URL,params:string;    AList:TStrings;
begin
  try
    MS:=TMemoryStream.create;     AList:=TStringList.Create;
    url:= c_url;
    params:='grant_type='+EncodeURLElement('password')+'&'
            +'username='+EncodeURLElement(c_username)+'&'
            +'password='+EncodeURLElement(c_password)+'&'
            +'client_id='+EncodeURLElement(c_client_id);
    try
      if MyHttpPostURL(URL, Params, MS) then begin
        Memo1.Lines.add('Boolean:true');
      end else begin
        Memo1.Lines.add('Boolean:false');
      end;
      MS.Position:=0;
      AList.LoadFromStream(MS);
      memo1.Lines.add(AList.text);
    except
      on E:Exception do begin
        ShowMessage(E.Message);
      end;
    end;
  finally
    MS.Free;   AList.Free;
  end;
end;

使用Synapse时,MyHttpPostURL返回true(无报错),但服务器返回“访问被拒绝”,提示无权限访问目标地址。


内容的提问来源于stack exchange,提问作者Aias Meranos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 06:58:12