GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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
Filter options
  • doc/api
    • http.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/http.md‎

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 numberDiff line numberDiff line change
@@ -2287,7 +2287,7 @@ The `callback` is invoked with a single argument that is an instance of
22872287
JSON fetching example:
22882288

22892289
```js
2290-
http.get('http://nodejs.org/dist/index.json', (res) => {
2290+
http.get('http://localhost:8000/', (res) => {
22912291
const { statusCode } = res;
22922292
const contentType = res.headers['content-type'];
22932293

@@ -2322,6 +2322,16 @@ http.get('http://nodejs.org/dist/index.json', (res) => {
23222322
}).on('error', (e) => {
23232323
console.error(`Got error: ${e.message}`);
23242324
});
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);
23252335
```
23262336

23272337
## `http.globalAgent`

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.