Question

How can I decode & parse a URL so I can use it as POST parameters.

continue=http%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&rm=false&dsh=..

var
 URL:String;
 Data:TStringList;
 MemoryStream:TMemoryStream;
begin
IdHTTP1.Post(URL, Data, MemoryStream);
Was it helpful?

Solution

You can do it all with TIdURI:

  • To decode use TIdURI.URLDecode(...).
  • To parse, pass the decoded URI to TIdURI.Create.

Putting it together you'd have something like this:

var
  URI: TIdURI;
....
URI := TIdURI.Create(TIdURI.URLDecode(EncodedURI));
try
  // Protocol = URI.Protocol
  // Username = URI.Username
  // Password = URI.Password
  // Host = URI.Host
  // Port = URI.Port
  // Path = URI.Path
  // Query = URI.Params
finally
  URI.Free;
end;

With acknowledgement to these answers:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top