在数据采集服务器中的用户授权失败时,是否可以更改响应代码? [英] Is it possible to change the Response Code when user authorization fails in a datasnap server?
问题描述
当用户授权失败时,是否可以更改DataSnap(Delphi XE3)服务器中的HTTP响应代码?目前,它正在返回HTTP / 1.1 500内部服务器错误,这可能发生在许多其他情况,并不帮助描述问题。
Is it possible to change the HTTP Response Code in my DataSnap (Delphi XE3) server when user authorization fails? Currently it's returning HTTP/1.1 500 Internal Server Error, which can happen in many other scenarios, and doesn't help describe the problem.
同样的想法,是否可以更改默认响应体?目前,它正在返回 {error:USER没有权限执行请求的操作。} ,这很好,但如果可能,我想返回一个自定义的JSON对象。
Along the same idea, is it possible to change the default Response Body? Currently, it's returning {"error":"USER is not authorized to perform the requested action."}, which is fine, but I'd like to return a custom JSON object if possible.
感谢您的时间!
推荐答案
我最终执行代码在TDSAuthenticationManager.OnUserAuthorize中看起来像这样。
I ended up executing code that looked like this in TDSAuthenticationManager.OnUserAuthorize
if valid = false then
begin
GetInvocationMetadata.ResponseCode := 403;
GetInvocationMetadata.ResponseMessage := JSONResponseObject.ToString;
GetInvocationMetadata.ResponseContent := JSONResponseOjbect.ToString;
end
这篇关于在数据采集服务器中的用户授权失败时,是否可以更改响应代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!