Extract URL parameters from URL? In DELPHI

I have an incoming URL which I need to catch some parameters, our project is in Delphi. Here is what the URL looks like :

I need to get the value right after "state" and before'code'. I am using a class from System.Net.URLClient.TURI

AURL = ''
uri := TUri.Create(AUrl); 
returnstate := uri.ParameterByName['state'];

When using the parameterbyname it's empty. Appreciate the help.


  • As stated in the comments, you need to decode the response parameter.

    First step is percent decoding. You can use TURLEnconding for this.

    Response := TURLEncoding.Decode(uri.ParameterByName['response']);

    Then, break the embedded response at the encoded & characters. There may be an easier way to do it, but you could use Pos, or a TPerlRegEx. I think a quick way would be to use a TStringList and set the & as the Delimiter character:

    ResponseParams := TStringList.Create;
    ResponseParams.Delimiter := '&';
    ResponseParams.DelimitedText := Response;

    Then, you have name-value pairs and a standard TStringList will separate those for you.