如何解析网址? [英] How do I parse a web URL?
本文介绍了如何解析网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要能够将网址分解成不同的细分。以此路径为例:
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/something_else.html?param1=val¶m2=val#nose
\__/ \___/ \______/ \_____________________/ \__/\____________________________/ \___________________/ \__/
| | | | | | | |
Scheme Username Password Host Port Path Query Fragment
这应该分解如下: p>
This should break down as follows:
Protocol: HTTP
Username: login
Password: password
Host: somehost.somedomain.com
Port: 8080
Path Info: /some_path/something_else.html
Query String: param1=val¶m2=val
如何在Delphi中执行此操作?有什么准备好了,可以为我分裂吗?如果没有,我该如何去解析所有不同的可能格式?这是假设它甚至可能是一个不同的协议,如HTTPS或RTSP。
How can I do this in Delphi? Is there something ready made which can split this up for me? If not, how do I go about parsing all the different possible formats? This is assuming that it might even be a different protocol, such as HTTPS or RTSP.
推荐答案
XE2附带Indy,一个 TIdURI
类,例如:
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;
这篇关于如何解析网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文