|
@ -1568,9 +1568,13 @@ added to the [`'request'`][] event. |
|
|
## http.get(options[, callback]) |
|
|
## http.get(options[, callback]) |
|
|
<!-- YAML |
|
|
<!-- YAML |
|
|
added: v0.3.6 |
|
|
added: v0.3.6 |
|
|
|
|
|
changes: |
|
|
|
|
|
- version: v7.5.0 |
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/10638 |
|
|
|
|
|
description: The `options` parameter can be a WHATWG `URL` object. |
|
|
--> |
|
|
--> |
|
|
|
|
|
|
|
|
* `options` {Object | string} Accepts the same `options` as |
|
|
* `options` {Object | string | URL} Accepts the same `options` as |
|
|
[`http.request()`][], with the `method` always set to `GET`. |
|
|
[`http.request()`][], with the `method` always set to `GET`. |
|
|
Properties that are inherited from the prototype are ignored. |
|
|
Properties that are inherited from the prototype are ignored. |
|
|
* `callback` {Function} |
|
|
* `callback` {Function} |
|
@ -1636,9 +1640,13 @@ requests. |
|
|
## http.request(options[, callback]) |
|
|
## http.request(options[, callback]) |
|
|
<!-- YAML |
|
|
<!-- YAML |
|
|
added: v0.3.6 |
|
|
added: v0.3.6 |
|
|
|
|
|
changes: |
|
|
|
|
|
- version: v7.5.0 |
|
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/10638 |
|
|
|
|
|
description: The `options` parameter can be a WHATWG `URL` object. |
|
|
--> |
|
|
--> |
|
|
|
|
|
|
|
|
* `options` {Object | string} |
|
|
* `options` {Object | string | URL} |
|
|
* `protocol` {string} Protocol to use. Defaults to `http:`. |
|
|
* `protocol` {string} Protocol to use. Defaults to `http:`. |
|
|
* `host` {string} A domain name or IP address of the server to issue the |
|
|
* `host` {string} A domain name or IP address of the server to issue the |
|
|
request to. Defaults to `localhost`. |
|
|
request to. Defaults to `localhost`. |
|
@ -1677,8 +1685,9 @@ added: v0.3.6 |
|
|
Node.js maintains several connections per server to make HTTP requests. |
|
|
Node.js maintains several connections per server to make HTTP requests. |
|
|
This function allows one to transparently issue requests. |
|
|
This function allows one to transparently issue requests. |
|
|
|
|
|
|
|
|
`options` can be an object or a string. If `options` is a string, it is |
|
|
`options` can be an object, a string, or a [`URL`][] object. If `options` is a |
|
|
automatically parsed with [`url.parse()`][]. |
|
|
string, it is automatically parsed with [`url.parse()`][]. If it is a [`URL`][] |
|
|
|
|
|
object, it will be automatically converted to an ordinary `options` object. |
|
|
|
|
|
|
|
|
The optional `callback` parameter will be added as a one time listener for |
|
|
The optional `callback` parameter will be added as a one time listener for |
|
|
the [`'response'`][] event. |
|
|
the [`'response'`][] event. |
|
@ -1750,6 +1759,18 @@ There are a few special headers that should be noted. |
|
|
* Sending an Authorization header will override using the `auth` option |
|
|
* Sending an Authorization header will override using the `auth` option |
|
|
to compute basic authentication. |
|
|
to compute basic authentication. |
|
|
|
|
|
|
|
|
|
|
|
Example using a [`URL`][] as `options`: |
|
|
|
|
|
|
|
|
|
|
|
```js |
|
|
|
|
|
const { URL } = require('url'); |
|
|
|
|
|
|
|
|
|
|
|
const options = new URL('http://abc:xyz@example.com'); |
|
|
|
|
|
|
|
|
|
|
|
const req = http.request(options, (res) => { |
|
|
|
|
|
// ... |
|
|
|
|
|
}); |
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
[`'checkContinue'`]: #http_event_checkcontinue |
|
|
[`'checkContinue'`]: #http_event_checkcontinue |
|
|
[`'listening'`]: net.html#net_event_listening |
|
|
[`'listening'`]: net.html#net_event_listening |
|
|
[`'request'`]: #http_event_request |
|
|
[`'request'`]: #http_event_request |
|
@ -1757,6 +1778,7 @@ There are a few special headers that should be noted. |
|
|
[`Agent`]: #http_class_http_agent |
|
|
[`Agent`]: #http_class_http_agent |
|
|
[`EventEmitter`]: events.html#events_class_eventemitter |
|
|
[`EventEmitter`]: events.html#events_class_eventemitter |
|
|
[`TypeError`]: errors.html#errors_class_typeerror |
|
|
[`TypeError`]: errors.html#errors_class_typeerror |
|
|
|
|
|
[`URL`]: url.html#url_the_whatwg_url_api |
|
|
[`agent.createConnection()`]: #http_agent_createconnection_options_callback |
|
|
[`agent.createConnection()`]: #http_agent_createconnection_options_callback |
|
|
[`destroy()`]: #http_agent_destroy |
|
|
[`destroy()`]: #http_agent_destroy |
|
|
[`http.Agent`]: #http_class_http_agent |
|
|
[`http.Agent`]: #http_class_http_agent |
|
|