URL 和 NSURL 格式解析

URL 和 NSURL 格式解析

字数973阅读46评论0喜欢0

1. URL 是什么?

统一资源定位符(Uniform Resource Locator,缩写为URL),又叫做网页地址,是互联网上标准的资源的地址(Address)。互联网上的每个文件都有一个唯一的URL,它包含的信息指出文件的位置以及浏览器应该怎么处理它。

统一资源定位符:

定位资源

确定资源出自哪里(可以用什么方式解析)

2. URL 定义格式

注意,Windows 主机不区分 URL 大小写,但是,Unix/Linux 主机区分大小写。

url 的基本定义:

// url 编码格式foo://example.com:8042/over/there?name=ferret#nose  \_/ \______________/ \________/\_________/ \__/|        |              |        |        |scheme    authority        path    query  fragment

URL由三部分组成:资源类型、存放资源的主机域名、资源文件名

scheme://host.domain:port/path/filenamescheme - 定义因特网服务的类型。最常见的类型是 httphost - 定义域主机(http 的默认主机是 www)domain - 定义因特网域名,比如 w3school.com.cn:port - 定义主机上的端口号(http 的默认端口号是80)path - 定义服务器上的路径(如果省略,则文档必须位于网站的根目录中)。filename - 定义文档/资源的名称

常见的 scheme

file      资源是本地计算机上的文件。格式file://ftp        通过 FTP访问资源。格式 FTP://gopher    通过 Gopher 协议访问该资源。 http      通过 HTTP 访问该资源。 格式 HTTP://https      通过安全的 HTTPS 访问该资源。 格式 target=_blank>HTTPS://mailto    资源为电子邮件地址,通过 SMTP 访问。 格式 mailto:MMS        通过 支持MMS(流媒体)协议的播放该资源。(代表软件:Windows Media Player)格式 MMS://ed2k      通过 支持ed2k(专用下载链接)协议的P2P软件访问该资源。(代表软件:电驴) 格式 ed2k://Flashget  通过 支持Flashget:(专用下载链接)协议的P2P软件访问该资源。(代表软件:快车) 格式 Flashget://thunder    通过 支持thunder(专用下载链接)协议的P2P软件访问该资源。(代表软件:迅雷) 格式 thunder://news      通过 NNTP 访问该资源。

常见的URL中定位和标识的服务或文件:

http:        文件在WEB服务器上.

file:        文件在您自己的局部系统或匿名服务器上

ftp:        文件在FTP服务器上

gopher:      文件在gopher服务器上

wais:        文件在wais服务器上

news:        文件在Usenet服务器上

telnet:      连接到一个支持Telnet远程登录的服务器上

3. NSURL

NSURL 继承自 NSObject, NSURL 就是对统一资源定位符的数据封装。包含的也就是组成 url 的三部分信息。

NSURL相关属性

publicvarabsoluteString:String{get}    publicvarrelativeString:String? {get}// The relative portion of a URL.  If baseURL is nil, or if the receiver is itself absolute, this is the same as absoluteString@NSCopyingpublicvarbaseURL:NSURL? {get}// may be nil.@NSCopyingpublicvarabsoluteURL:NSURL{get}// if the receiver is itself absolute, this will return self./* Any URL is composed of these two basic pieces.  The full URL would be the concatenation of [myURL scheme], ':', [myURL resourceSpecifier]

*/publicvarscheme:String{get}    publicvarresourceSpecifier:String{get}/* If the URL conforms to rfc 1808 (the most common form of URL), the following accessors will return the various components; otherwise they return nil.  The litmus test for conformance is as recommended in RFC 1808 - whether the first two characters of resourceSpecifier is @"//".  In all cases, they return the component's value after resolving the receiver against its base URL.

*/publicvarhost:String? {get}@NSCopyingpublicvarport:NSNumber? {get}    publicvaruser:String? {get}    publicvarpassword:String? {get}    publicvarpath:String? {get}    publicvarfragment:String? {get}    publicvarparameterString:String? {get}    publicvarquery:String? {get}    publicvarrelativePath:String? {get}// The same as path if baseURL is nil/* Determines if a given URL string's path represents a directory (i.e. the path component in the URL string ends with a '/' character). This does not check the resource the URL refers to.

*/@available(iOS9.0, *)    publicvarhasDirectoryPath:Bool{get}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值