I use, with Delphi 10.3.1, a TNetHTTPClient with GET command and I need to get the final URL after a page redirection(s). Is there any property or function for it ? Thx.
1 Answer
It seems there's no direct (public) access to request instance associated with response. A hacky solution relies on:
IHTTPResponse
returned is implemented byTHTTPResponse
(implementation detail)- protected access to
FRequest
field ofTHTTPResponse
Then you can use following code to access request instance:
type
THTTPResponseAccess = class(THTTPResponse);
procedure TForm2.Button1Click(Sender: TObject);
var
Response: THTTPResponse;
Request: IURLRequest;
begin
Response := NetHTTPClient1.Get('http://google.com') as THTTPResponse;
Request := THTTPResponseAccess(Response).FRequest;
ShowMessage(Request.URL.ToString);
end;
Output is:
http://www.google.com/