1
我是新來的這個delphi datasnap的東西,幾乎沒有任何有用的文件。如何篩選Delphi datasnap rest服務器上的請求?
我按照this guide設置了一個簡單的休息服務器。現在我想定義我自己的身份驗證協議。
據我所知。在調用服務器類方法之前,來自遠程客戶端的所有請求都將通過WebModule方法進行處理。到目前爲止,我能夠捕獲客戶端IP地址和這樣的請求URL路徑:
procedure TWebModule1.WebModuleBeforeDispatch(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
ShowMessage(request.RemoteAddr); // adress where request came from
ShowMessage(request.PathInfo); // url path
Response.SetCustomHeader('access-control-allow-origin','*');
if FServerFunctionInvokerAction <> nil then
FServerFunctionInvokerAction.Enabled := AllowServerFunctionInvoker;
end;
我怎麼能:
拒絕請求依賴於特定的IP地址,並返回401狀態碼客戶在達到類方法之前?
重定向客戶端到另一個方法?例如:重定向此請求:
request = new XMLHttpRequest();
request.open('GET', 'http://localhost:8080/datasnap/rest/TServerMethods1/ReverseString/blah', true);
以另一種方法代替ReverseString。
您向HTTP響應添加了CORS標頭(access-control-allow-origin)。知道這是否按預期工作是有趣的,允許跨域請求。 – mjn 2014-09-30 14:15:44