我们有一个在 Delphi Seattle 10 中开发的 ISAPI webbroker 应用程序。它支持使用 SSO Azure 登录。
我们使用 TREST 组件来获取访问代码和图形数据。
它大部分时间都有效,但每天 1 或 2 次它会给我们这个错误:
REST 请求失败:打开请求时出错:(6)句柄无效
设置是:我们在 datammodule 中有 3 个其余组件
RESTClientsso: TRESTClient;
RESTRequestsso: TRESTRequest;
RESTResponseSSO: TRESTResponse;
我们将 Rest Component 分配给一个类
AzureSSOClass:=TAzureSSOClass.Create;
try
AzureSSOClass.RESTClientSSO:=RESTClientsso;
AzureSSOClass.RESTRequesTSSO:=RESTRequestsso;
AzureSSOClass.RESTResponseSSO:=RESTResponseSSO;
然后我们有这个函数可以在 RESTRequestSSO.Execute 上发出警报;
function TAzureSSOClass.getAccessCode: Boolean;
var
LJSONObject : TJSONObject;
infoRest : String;
s:String;
begin
result :=true;
s:='https://login.microsoftonline.com/';
s:=s+FTenant+'/oauth2/token';
RESTClientSSO.BaseURL:=s;
RESTClientSSO.HandleRedirects:=true;
RESTRequestSSO.Method :=TRESTRequestMethod.rmPOST;
// paramter..
RestRequestSSO.Params.Clear;
RestRequestSSO.Params.AddItem('grant_type', 'authorization_code');
RestRequestSSO.Params.AddItem('code', Fcode);
RestRequestSSO.Params.AddItem('client_id', FClientID);
RestRequestSSO.Params.AddItem('resource', 'https://graph.windows.net');
RestRequestSSO.Params.AddItem('client_secret',FClientSecret);
RESTRequestSSO.Execute; // here we get the error
inforest:=RESTResponseSSO.Content;
try
LJSONObject := TJSONObject.ParseJSONValue(TEncoding.ASCII.GetBytes(infoRest), 0) as TJSONObject;
FAccessCode:=LJSONObject.Values['access_token'].Value;
Fidtoken:=LJSONObject.Values['access_token'].Value;
GetPayload;
ParseToken;
finally
LJSONObject.Free
end;
if FAccessCode ='' then
begin
Ferror:='error getting access code';
result:=false;
end;
end;
知道为什么会发生这种情况,在 webbroker 应用程序中执行此操作不是一个好主意吗?