How do I parse a web URL?

前端 未结 2 1942
心在旅途
心在旅途 2021-01-02 00:09

I need to be able to break a URL down into different segments. Take this path for example:

http://login:password@somehost.somedomain.com:8080/some_path/somet         


        
2条回答
  •  余生分开走
    2021-01-02 00:22

    XE2 ships with Indy, which has a TIdURI class for that purpose, eg:

    uses
      ..., IdURI;
    
    var
      URI: TIdURI;
    
    URI := TIdURI.Create('http://login:password@somehost.somedomain.com:8080/some_path/something_else.html?param1=val¶m2=val');
    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;
    

提交回复
热议问题