@@ -4,7 +4,7 @@ Node.js Documentation
4
4
https://nodejs.org
5
5
6
6
==============================================================================
7
- CONTENTS *node-api-contents*
7
+ CONTENTS *node-api-http -contents*
8
8
9
9
1. Intro | node-api-http |
10
10
2. Methods | node-api-http-methods |
@@ -79,14 +79,14 @@ Returns a new instance of *node-api-http_class_http_server*.
79
79
The `requestListener` is a function which is automatically
80
80
added to the `' request' ` event.
81
81
82
-
82
+
83
83
------------------------------------------------------------------------------
84
84
http.createClient([port][, host]) *node-api-http.createClient()*
85
85
86
86
Constructs a new HTTP client. `port` and `host` refer to the server to be
87
87
connected to.
88
88
89
-
89
+
90
90
------------------------------------------------------------------------------
91
91
http.request(options[, callback]) *node-api-http.request()*
92
92
@@ -99,7 +99,7 @@ automatically parsed with [url.parse()][].
99
99
Options:
100
100
101
101
* `protocol` : Protocol to use. Defaults to `' http' ` .
102
-
102
+
103
103
* `host` : A domain name or IP address of the server to issue the request to.
104
104
Defaults to `' localhost' ` .
105
105
* `hostname ` : Alias for `host` . To support `url.parse ()` `hostname ` is
@@ -124,24 +124,24 @@ Options:
124
124
* `Agent` object: explicitly use the passed in `Agent` .
125
125
* `false` : opts out of connection pooling with an Agent, defaults request to
126
126
`Connection: close`.
127
-
127
+
128
128
The optional `callback` parameter will be added as a one time listener for
129
129
the ['response' ][] event.
130
-
131
-
130
+
131
+
132
132
`http.request ()` returns an instance of the [http.ClientRequest][]
133
133
class. The `ClientRequest` instance is a writable stream. If one needs to
134
134
upload a file with a POST request, then write to the `ClientRequest` object.
135
-
136
-
135
+
136
+
137
137
Example:
138
-
139
-
138
+
139
+
140
140
>
141
141
var postData = querystring.stringify({
142
142
'msg' : 'Hello World!'
143
143
});
144
-
144
+
145
145
var options = {
146
146
hostname: 'www.google.com',
147
147
port: 80,
@@ -152,7 +152,7 @@ Options:
152
152
'Content-Length': postData.length
153
153
}
154
154
};
155
-
155
+
156
156
var req = http.request(options, function(res) {
157
157
console.log('STATUS: ' + res.statusCode);
158
158
console.log('HEADERS: ' + JSON.stringify(res.headers));
@@ -164,45 +164,45 @@ Options:
164
164
console.log('No more data in response.')
165
165
})
166
166
});
167
-
167
+
168
168
req.on('error', function(e) {
169
169
console.log('problem with request: ' + e.message);
170
170
});
171
-
171
+
172
172
// write data to request body
173
173
req.write(postData);
174
174
req.end();
175
- <
176
-
175
+ <
176
+
177
177
Note that in the example `req.end()` was called. With `http.request()` one
178
178
must always call `req.end()` to signify that you're done with the request -
179
179
even if there is no data being written to the request body.
180
-
181
-
180
+
181
+
182
182
If any error is encountered during the request (be that with DNS resolution,
183
183
TCP level errors, or actual HTTP parse errors) an `'error'` event is emitted
184
184
on the returned request object.
185
-
186
-
185
+
186
+
187
187
There are a few special headers that should be noted.
188
-
189
-
190
-
188
+
189
+
190
+
191
191
* Sending a 'Connection: keep-alive' will notify io.js that the connection to
192
192
the server should be persisted until the next request.
193
-
193
+
194
194
* Sending a 'Content-length' header will disable the default chunked encoding.
195
-
195
+
196
196
* Sending an 'Expect' header will immediately send the request headers.
197
197
Usually, when sending 'Expect: 100-continue', you should both set a timeout
198
198
and listen for the `continue ` event. See RFC2616 Section 8.2.3 for more
199
199
information.
200
-
200
+
201
201
* Sending an Authorization header will override using the `auth` option
202
202
to compute basic authentication.
203
+
203
204
204
-
205
-
205
+
206
206
------------------------------------------------------------------------------
207
207
http.get(options[, callback]) *node-api-http.get()*
208
208
@@ -220,7 +220,7 @@ Example:
220
220
});
221
221
<
222
222
223
-
223
+
224
224
225
225
==============================================================================
226
226
PROPERTIES *node-api-http-properties*
@@ -230,22 +230,22 @@ PROPERTIES *node-api-http-properties*
230
230
231
231
A list of the HTTP methods that are supported by the parser.
232
232
233
-
233
+
234
234
------------------------------------------------------------------------------
235
235
`STATUS_CODES` {Object} *node-api-http.STATUS_CODES*
236
236
237
237
A collection of all the standard HTTP response status codes, and the
238
238
short description of each. For example, `http.STATUS_CODES[404] === 'Not
239
239
Found'`.
240
240
241
-
241
+
242
242
------------------------------------------------------------------------------
243
243
http.globalAgent *node-api-http.globalAgent*
244
244
245
245
Global instance of Agent which is used as the default for all http client
246
246
requests.
247
247
248
-
248
+
249
249
------------------------------------------------------------------------------
250
250
http.IncomingMessage *node-api-http.IncomingMessage*
251
251
@@ -257,6 +257,6 @@ headers and data.
257
257
It implements the [Readable Stream][] interface, as well as the
258
258
following additional events, methods, and properties.
259
259
260
+
260
261
261
-
262
- vim:tw=78:ts=8:ft=help
262
+ vim:tw=78:ts=8:ft=help
0 commit comments