request.url
- 类型:<string>
请求 URL 字符串。它仅包含实际 HTTP 请求中存在的 URL。如果请求是:
【Request URL string. This contains only the URL that is present in the actual HTTP request. If the request is:】
GET /status?name=ryan HTTP/1.1
Accept: text/plain 那么 request.url 将会是:
【Then request.url will be:】
'/status?name=ryan' 要将 URL 解析为各部分,可以使用 new URL():
【To parse the url into its parts, new URL() can be used:】
$ node
> new URL('/status?name=ryan', 'http://example.com')
URL {
href: 'http://example.com/status?name=ryan',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/status',
search: '?name=ryan',
searchParams: URLSearchParams { 'name' => 'ryan' },
hash: ''
}