残念ながら、カスタム ヘッダーはクリアされて無視されますTDSRestRequest.GetHTTP
(ユニットTDSRestRequest
の実装では隠されますDatasnap.DSClientRest
)。この回避策を試してください:
uses
Datasnap.DSHTTP, IdHTTPHeaderInfo;
const
SUserAgent = 'MyUserAgent';
type
TDSHTTPEx = class(TDSHTTP)
constructor Create(AOwner: TComponent; const AIPImplementationID: string); override;
end;
TDSHTTPSEx = class(TDSHTTPS)
constructor Create(const AIPImplementationID: string); override;
end;
{ TDSHTTPEx }
constructor TDSHTTPEx.Create(AOwner: TComponent; const AIPImplementationID: string);
begin
inherited Create(AOwner, AIPImplementationID);
with Request.GetObject as TIdRequestHeaderInfo do
UserAgent := SUserAgent;
end;
{ TDSHTTPSEx }
constructor TDSHTTPSEx.Create(const AIPImplementationID: string);
begin
inherited Create(AIPImplementationID);
with Request.GetObject as TIdRequestHeaderInfo do
UserAgent := SUserAgent;
end;
initialization
TDSHTTP.UnregisterProtocol('http');
TDSHTTP.RegisterProtocol('http', TDSHTTPEx);
TDSHTTP.UnregisterProtocol('https');
TDSHTTPS.RegisterProtocol('https', TDSHTTPSEx);
finalization
TDSHTTP.UnregisterProtocol('http');
TDSHTTP.UnregisterProtocol('https');
end.