目录 搜索
Guides Access control CORS Authentication Browser detection using the user agent Caching Caching FAQ Compression Conditional requests Connection management in HTTP 1.x Content negotiation Content negotiation: List of default Accept values Cookies CSP Messages Overview Protocol upgrade mechanism Proxy servers and tunneling Proxy servers and tunneling: Proxy Auto-Configuration (PAC) file Public Key Pinning Range requests Redirections Resources and specifications Resources and URIs Response codes Server-Side Access Control Session Guides: Basics Basics of HTTP Choosing between www and non-www URLs Data URIs Evolution of HTTP Identifying resources on the Web MIME Types MIME types: Complete list of MIME types CSP Content-Security-Policy Content-Security-Policy-Report-Only CSP: base-uri CSP: block-all-mixed-content CSP: child-src CSP: connect-src CSP: default-src CSP: font-src CSP: form-action CSP: frame-ancestors CSP: frame-src CSP: img-src CSP: manifest-src CSP: media-src CSP: object-src CSP: plugin-types CSP: referrer CSP: report-uri CSP: require-sri-for CSP: sandbox CSP: script-src CSP: style-src CSP: upgrade-insecure-requests CSP: worker-src Headers Accept Accept-Charset Accept-Encoding Accept-Language Accept-Ranges Access-Control-Allow-Credentials Access-Control-Allow-Headers Access-Control-Allow-Methods Access-Control-Allow-Origin Access-Control-Expose-Headers Access-Control-Max-Age Access-Control-Request-Headers Access-Control-Request-Method Age Allow Authorization Cache-Control Connection Content-Disposition Content-Encoding Content-Language Content-Length Content-Location Content-Range Content-Type Cookie Cookie2 Date DNT ETag Expect Expires Forwarded From Headers Host If-Match If-Modified-Since If-None-Match If-Range If-Unmodified-Since Keep-Alive Large-Allocation Last-Modified Location Origin Pragma Proxy-Authenticate Proxy-Authorization Public-Key-Pins Public-Key-Pins-Report-Only Range Referer Referrer-Policy Retry-After Server Set-Cookie Set-Cookie2 SourceMap Strict-Transport-Security TE Tk Trailer Transfer-Encoding Upgrade-Insecure-Requests User-Agent User-Agent: Firefox Vary Via Warning WWW-Authenticate X-Content-Type-Options X-DNS-Prefetch-Control X-Forwarded-For X-Forwarded-Host X-Forwarded-Proto X-Frame-Options X-XSS-Protection Methods CONNECT DELETE GET HEAD Methods OPTIONS PATCH POST PUT Status 100 Continue 101 Switching Protocols 200 OK 201 Created 202 Accepted 203 Non-Authoritative Information 204 No Content 205 Reset Content 206 Partial Content 300 Multiple Choices 301 Moved Permanently 302 Found 303 See Other 304 Not Modified 307 Temporary Redirect 308 Permanent Redirect 400 Bad Request 401 Unauthorized 403 Forbidden 404 Not Found 405 Method Not Allowed 406 Not Acceptable 407 Proxy Authentication Required 408 Request Timeout 409 Conflict 410 Gone 411 Length Required 412 Precondition Failed 413 Payload Too Large 414 URI Too Long 415 Unsupported Media Type 416 Range Not Satisfiable 417 Expectation Failed 426 Upgrade Required 428 Precondition Required 429 Too Many Requests 431 Request Header Fields Too Large 451 Unavailable For Legal Reasons 500 Internal Server Error 501 Not Implemented 502 Bad Gateway 503 Service Unavailable 504 Gateway Timeout 505 HTTP Version Not Supported 511 Network Authentication Required Status
文字

HTTP 请求的目标被称为“资源”,这个性质没有进一步定义; 它可以是文档,照片或其他任何东西。每个资源都由 HTTP 中用于标识资源的统一资源标识符(URI)标识。

Web 上资源的身份和位置主要由一个 URL(统一资源定位器,一种 URI)提供。有时候,原因是同一个 URI 没有给出身份和位置:Alt-Svc当请求的资源需要客户访问另一个位置时,HTTP 使用特定的 HTTP 头。

网址(URLs)和URN

网址(URLs)

最常见的 URI 形式是统一资源定位符(URL),称为网址

https://developer.mozilla.org
https://developer.mozilla.org/en-US/docs/Learn/https://developer.mozilla.org/en-US/search?q=URL

任何这些 URL 都可以输入到浏览器的地址栏中,以告诉它加载关联的页面(资源)。

一个 URL 由不同的部分组成,其中一些是强制性的,另一些是可选的。一个更复杂的例子可能是这样的:

http://www.example.com:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument

URNs

统一资源名称(URN)是在特定名称空间中按名称标识资源的 URI。

urn:isbn:9780141036144urn:ietf:rfc:7230

两个 URN 相对应

  • 乔治奥威尔的“九八十四”一书,

  • IETF 规范7230,超文本传输协议(HTTP / 1.1):消息语法和路由。

统一资源标识符(URI)的语法

计划或协议

http://是协议。它指示浏览器必须使用哪种协议。通常它是 HTTP 协议或其安全版本 HTTPS。Web 需要其中的一种,但浏览器也知道如何处理其他协议,如mailto:(打开邮件客户端)或ftp:处理文件传输,所以如果您看到这样的协议,请不要感到惊讶。常用的方案是:

方案

描述

数据 data

数据 URI

文件 file

主机特定的文件名

FTP

文件传输协议

HTTP / HTTPS

超文本传输协议(安全)

邮寄地址 mailto

电子邮件地址

SSH

安全的外壳

tel

电话

urn

统一资源名称

视图源

资源的源代码

ws / wss

(加密)WebSocket连接

权威

www.example.com是管辖命名空间的域名或权威。它指示正在请求哪个 Web 服务器。或者,可以直接使用 IP 地址,但由于它不太方便,因此不常用在 Web 上。

港口(出口或接口)

:80是这个实例中的端口。它表示用于访问 Web 服务器上资源的技术“门”。如果 Web 服务器使用 HTTP 协议的标准端口(HTTP 为80,HTTPS 为443)来授予其资源访问权限,通常会忽略它。否则它是强制性的。

路径

/path/to/myfile.html是 Web 服务器上资源的路径。在 Web 早期,这样的路径代表了 Web 服务器上的物理文件位置。如今,它主要是一个 Web 服务器处理的抽象,没有任何物理现实。

询问

?key1=value1&key2=value2是提供给 Web 服务器的额外参数。这些参数是用&符号分隔的键/值对列表。在将资源返回给用户之前,Web 服务器可以使用这些参数来执行额外的工作。每个 Web 服务器都有自己的参数规则,知道特定 Web 服务器如何处理参数的唯一可靠方法是询问 Web 服务器所有者。

分段

#SomewhereInTheDocument是资源本身另一部分的锚点。锚表示资源内部的一种“书签”,为浏览器指示位于该“书签”位置的内容。例如,在 HTML 文档中,浏览器将滚动到定义锚点的位置; 在视频或音频文档上,浏览器将尝试转到锚点代表的时间。值得注意的是,#之后的部分(也称为片段标识符)永远不会被发送到请求的服务器。

示例

https://developer.mozilla.org/en-US/docs/Learn
tel:+1-816-555-1212git@github.com:mdn/browser-compat-data.git
ftp://example.org/resource.txt
urn:isbn:9780141036144

产品规范

规范

标题

RFC 7230,第2.7节:统一资源标识符

超文本传输协议(HTTP / 1.1):消息语法和路由

上一篇: 下一篇: