I know, this question has been asked before. Unfortunately, I didn't understand the answer(s). I would like to know my user's IP address for logging (via XData server) and for providing IP address specific functionality.
Please explain how.
Thanks Chris
Hi there...
Probably a number of ways to tackle this. What I've done on the XData Server side is just pickup the client IP address within a service ednpoint call. Eg:
TMyService.GetClientIP(ClientName: String):String;
begin
Result := TXDataOperationContext.Current.Request.RemoteIP;
SomeLoggingFunction(ClientName, Result);
end;
You pass it some kind of client identifier (for example) and then you can log it in whatever way suits you along with the IP address that it is related to. The usual caveats apply of course about using IP addresses for anything too serious due to the prevalence of VPNs and the like.
Thanks Andrew for your quick reply! I actually meant something like this:
procedure TForm1.WebHttpRequestResponse(Sender: TObject; AResponse: string);
begin
memoIP_info.Lines.Clear;
memoIP_info.Lines.Add(AResponse);
Req.OnResponse:=nil;
end;
procedure TForm1.GetMyIP;
begin
with WebHttpRequest1 do begin
URL := 'https://ip.seeip.org/geoip';
Command := httpGET;
ResponseType := rtText;
OnResponse := WebHttpRequestResponse;
Headers.Text := '';
Execute;
end;
end ;
which gives me this:
{"ip":"2a0a:a541:9951:0:9b8:3b65:fe82:48e5","continent_code":"EU","country":"Germany","country_code":"DE","country_code3":"DEU","latitude":51.0000,"longitude":9.0000,"timezone":"Europe\/Berlin","offset":3600,"asn":8422,"organization":"NetCologne Gesellschaft fur Telekommunikation mbH"}
This should work for me right now.
Ah! That's a slightly different question Glad you got what you were after.