GeezerVison is showing github.com — doc: sending http request to localhost to avoid https redirect · nodejs/node@aff0cd3
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: doc/api/http.md +11-1Lines changed: 11 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -2287,7 +2287,7 @@ The `callback` is invoked with a single argument that is an instance of |
2287 | 2287 | JSON fetching example: |
2288 | 2288 |
|
2289 | 2289 | ```js |
2290 | | -http.get('http://nodejs.org/dist/index.json', (res) => { |
| 2290 | +http.get('http://localhost:8000/', (res) => { |
2291 | 2291 | const { statusCode } = res; |
2292 | 2292 | const contentType = res.headers['content-type']; |
2293 | 2293 |
|
@@ -2322,6 +2322,16 @@ http.get('http://nodejs.org/dist/index.json', (res) => { |
2322 | 2322 | }).on('error', (e) => { |
2323 | 2323 | console.error(`Got error: ${e.message}`); |
2324 | 2324 | }); |
| 2325 | + |
| 2326 | +// Create a local server to receive data from |
| 2327 | +const server = http.createServer((req, res) => { |
| 2328 | + res.writeHead(200, { 'Content-Type': 'application/json' }); |
| 2329 | + res.end(JSON.stringify({ |
| 2330 | + data: 'Hello World!' |
| 2331 | + })); |
| 2332 | +}); |
| 2333 | + |
| 2334 | +server.listen(8000); |
2325 | 2335 | ``` |
2326 | 2336 |
|
2327 | 2337 | ## `http.globalAgent` |
|