Yaron 53 Posted December 19, 2019 Hi @Andrea Magni To improve security and statistics, I need access to the client's IP address when my function triggers in server.resources: [Path('projectX')] TProjectXServicesResource = class protected public [GET, Produces(TMediaType.TEXT_HTML)] function xHome([QueryParam] lang : String) : String; [POST, Consumes(TMediaType.MULTIPART_FORM_DATA), Produces(TMediaType.TEXT_HTML)] function xAction([FormParams] AParams: TArray<TFormParam>): String; end; function TProjectXServicesResource.xHome([QueryParam] lang : String) : String; begin // Need access to the client's IP here end; function TProjectXServicesResource.xAction([FormParams] AParams: TArray<TFormParam>) : String; begin // Need access to the client's IP here end; How can I obtain the client IP? Share this post Link to post
Yaron 53 Posted December 22, 2019 If anyone else is wondering how it's done, you need to add "[Context] marsRequest: TWebRequest;" and then the client's IP is available in "marsRequest.RemoteIP". [Path('projectX')] TProjectXServicesResource = class protected [Context] marsRequest: TWebRequest; public [GET, Produces(TMediaType.TEXT_HTML)] function xHome([QueryParam] lang : String) : String; [POST, Consumes(TMediaType.MULTIPART_FORM_DATA), Produces(TMediaType.TEXT_HTML)] function xAction([FormParams] AParams: TArray<TFormParam>): String; end; function TProjectXServicesResource.xHome([QueryParam] lang : String) : String; begin ShowMessage(marsRequest.RemoteIP); end; function TProjectXServicesResource.xAction([FormParams] AParams: TArray<TFormParam>) : String; begin ShowMessage(marsRequest.RemoteIP); end; Share this post Link to post
Andrea Magni 75 Posted May 12, 2020 Glad you solved, sorry being away so much 😉 Share this post Link to post
marcovaldo 1 Posted January 8, 2023 On 12/22/2019 at 12:09 PM, Yaron said: If anyone else is wondering how it's done, you need to add "[Context] marsRequest: TWebRequest;" and then the client's IP is available in "marsRequest.RemoteIP". [Path('projectX')] TProjectXServicesResource = class protected [Context] marsRequest: TWebRequest; public [GET, Produces(TMediaType.TEXT_HTML)] function xHome([QueryParam] lang : String) : String; [POST, Consumes(TMediaType.MULTIPART_FORM_DATA), Produces(TMediaType.TEXT_HTML)] function xAction([FormParams] AParams: TArray<TFormParam>): String; end; function TProjectXServicesResource.xHome([QueryParam] lang : String) : String; begin ShowMessage(marsRequest.RemoteIP); end; function TProjectXServicesResource.xAction([FormParams] AParams: TArray<TFormParam>) : String; begin ShowMessage(marsRequest.RemoteIP); end; Hi, I am following down this path - but no success: - marsRequest stays nil - Also ading [HeaderParam] and [QueryParam] stay empty. What I am looking for is having the RequestURL to create an auto refresh status page which autorefreshs after a short time. Don't want to set URL as constant string... Any hints how to retrieve the Request URL simplest way (Just scrolling through Demo Code, but not seeing the trees instead of the wood...) Kind Greetings, Marcovaldo Share this post Link to post
marcovaldo 1 Posted January 8, 2023 Solved. Need not the URL; generic meta refresh works for me.. Share this post Link to post