AFAIK it is not possibile (Delphi XE2).
I've used a little trink to have access to the raw headers.
However, this is really dirty! Use at you own risk!
The actual class request class is the TIdHTTPAppRequest (WARNING: Could be different for different type of webbroker app. I''ve not tested this code with different kind of datasnap app).
So the trick is:
Declare a class helper similar to the following:
TIdHTTPAppRequestHelper = class helper for TIdHTTPAppRequest
public
function GetRequestInfo: TIdEntityHeaderInfo;
end;
implementation
function TIdHTTPAppRequestHelper.GetRequestInfo: TIdEntityHeaderInfo;
begin
Result := FRequestInfo;
end;
In this way you can use this helper to have acccess to the protected FRequestInfo field.
In the OnAction event handler you can use the following code to have all the headers names:
procedure Twm.wmWebActionItem1Action(Sender: TObject; Request: TWebRequest;
Response: TWebResponse; var Handled: Boolean);
var
HeadersCount: Integer;
I: Integer;
sw: TStreamWriter;
begin
Response.ContentType := 'text/plain';
Response.ContentStream := TMemoryStream.Create;
sw := TStreamWriter.Create(Response.ContentStream);
try
HeadersCount := TIdHTTPAppRequest(Request).GetRequestInfo.RawHeaders.Count;
for I := 0 to HeadersCount - 1 do
sw.WriteLine(TIdHTTPAppRequest(Request).GetRequestInfo.RawHeaders.Names[I]);
finally
sw.Free;
end;
Handled := True;
end;
However, it is bad that TWebRequest do not allows to read the raw headers. That should be changed!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…