message.url


仅适用于从 http.Server 获得的请求。

请求的网址字符串。 这仅包含实际 HTTP 请求中存在的网址。 接受以下请求:

GET /status?name=ryan HTTP/1.1
Accept: text/plain

要将网址解析为它的部分:

new URL(request.url, `http://${request.getHeaders().host}`);

request.url'/status?name=ryan'request.getHeaders().host'localhost:3000' 时:

$ node
> new URL(request.url, `http://${request.getHeaders().host}`)
URL {
  href: 'http://localhost:3000/status?name=ryan',
  origin: 'http://localhost:3000',
  protocol: 'http:',
  username: '',
  password: '',
  host: 'localhost:3000',
  hostname: 'localhost',
  port: '3000',
  pathname: '/status',
  search: '?name=ryan',
  searchParams: URLSearchParams { 'name' => 'ryan' },
  hash: ''
}

Only valid for request obtained from http.Server.

Request URL string. This contains only the URL that is present in the actual HTTP request. Take the following request:

GET /status?name=ryan HTTP/1.1
Accept: text/plain

To parse the URL into its parts:

new URL(request.url, `http://${request.getHeaders().host}`);

When request.url is '/status?name=ryan' and request.getHeaders().host is 'localhost:3000':

$ node
> new URL(request.url, `http://${request.getHeaders().host}`)
URL {
  href: 'http://localhost:3000/status?name=ryan',
  origin: 'http://localhost:3000',
  protocol: 'http:',
  username: '',
  password: '',
  host: 'localhost:3000',
  hostname: 'localhost',
  port: '3000',
  pathname: '/status',
  search: '?name=ryan',
  searchParams: URLSearchParams { 'name' => 'ryan' },
  hash: ''
}