URI URL的区别

URI stands for Universal Resource Identifier

URL stands for Universal Resource Locator

URL其实是URI的一个子集,A URL is a subset of the URI popular protocols. These are protocols (http://, ftp://, mailto:)

 

I am a posting machine today! Anyway, for a while now I've been quite confused about the difference between URLs (Uniform Resource Locators) and URIs (Uniform Resource Identifiers). I finally decided to do a little research and try and identify the distinction. I found the following at the W3C's Contemporary View of Uniform Resource Identifiers:

"...a URL is a type of URI that identifies a resource via a representation of its primary access mechanism (e.g., its network "location"), rather than by some other attributes it may have. Thus as we noted, "http:" is a URI scheme. An http URI is a URL. The phrase "URL scheme" is now used infrequently, usually to refer to some subclass of URI schemes..."

However, as is typical with W3C documents and specs, there's a little too much technical mumbo-jumbo floating around in that explanation to satisfy anyone who doesn't balance their checkbook in binary, so I kept looking. Kenneth Fly's Web Site provides provided the following:

"URI stands for Universal Resource Identifier and URL stands for Universal Resource Locator. Often times people use the terms interchangably, which is not entirely correct. A URL is a subset of the URI popular protocols. These are protocols (http://, ftp://, mailto:). Therefore all URLs are URIs. The term URL is deprecated and the more correct term URI is used in technical documentation. All URIs are means to access a resource on the Internet and are a a technical short hand used to link to the resource. URIs always designate a method to access the resource and designate the specific resource to be accessed."

So...my terminology is apparently way out-dated and I need to start saying "URI" instead of "URL." Why? Because anything that has been deprecated is bad news (remember the evil <blink> tag?). Now I know, and knowing is half the battle.

 

来自:

http://www.bernzilla.com/item.php?id=100

### URIURL 的基本定义 URI(Uniform Resource Identifier)是一个更广泛的概念,用于唯一标识一个资源。它可以表示资源的名称、位置或路径等信息。URI 包含了 URL(Uniform Resource Locator)和 URN(Uniform Resource Name)两种子类型。URLURI 的一种具体形式,主要用于指定资源的位置[^1]。 在 WPF 中,URI 被广泛用于访问应用程序内部资源,例如图像、XAML 文件、样式等。WPF 使用 `pack://` 这种特定格式的 URI 来访问嵌入在程序集中的资源。例如,`pack://application:,,,/ResourceFile.xaml` 用于访问编译时已知的应用程序资源文件[^2]。 URL 则是标准的网络地址,通常用于标识互联网上的资源位置。例如,`http://www.example.com/resource.jpg` 是一个典型的 URL,它指定了资源在网络上的具体位置,并通过 HTTP 协议进行访问。 ### URI 在 WPF 中的独特用途 WPF 支持使用 `pack://` URI 方案来访问本地资源。这种方案允许应用程序直接引用嵌入在程序集中的资源,而无需依赖外部文件路径。例如,`pack://SiteOfOrigin:,,,/images/my.jpg` 用于访问源站点文件,即部署时从原始位置加载的资源[^3]。 这种方式与传统的 URL 不同,因为它不依赖于网络协议或远程服务器。相反,它是一种专门设计用于本地资源管理的机制,适用于应用程序内部的资源定位需求。 ### URIURL 的主要区别 URI 更加抽象,可以涵盖资源的名称、位置或路径信息,而 URL 仅用于描述资源的具体位置。此外,URI 可以使用多种不同的协议,包括但不限于 `file://`、`http://` 和 `pack://`。相比之下,URL 通常基于网络协议,如 HTTP 或 FTP。 在 WPF 应用程序中,`pack://` URI 是一种独特的资源访问方式,适用于嵌入式资源和内容文件的处理。它与传统的 URL 形成鲜明对比,因为后者主要用于网络资源的访问。 ### 示例代码:WPF 中的 URI 使用 以下是一个简单的示例,展示如何在 WPF 中使用 `pack://` URI 加载图像: ```csharp imgContent.Source = new BitmapImage(new Uri("pack://SiteOfOrigin:,,,/images/my.jpg")); ``` 这段代码将图像文件 `my.jpg` 从源站点加载到 `Image` 控件中。这种写法充分利用了 WPF 的资源管理能力,使得开发者能够灵活地访问本地或部署时的资源。 ### 相关问题
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值