-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_client.js
31 lines (19 loc) · 979 Bytes
/
http_client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
Send an HTTP POST request to http://localhost:8000 and pipe process.stdin into
it. Pipe the response stream to process.stdout.
Here's an example of how to use the `request` module to send a GET request,
piping the result to stdout:
var request = require('request');
request('http://beep.boop:80/').pipe(process.stdout);
To make a POST request, just call `request.post()` instead of `request()`:
var request = require('request');
var r = request.post('http://beep.boop:80/');
The `r` object that you get back from `request.post()` is a readable+writable
stream so you can pipe a readable stream into it (`src.pipe(r)`) and you can
pipe it to a writable stream (`r.pipe(dst)`).
You can even chain both steps together: src.pipe(r).pipe(dst);
Hint: for your code, src will be process.stdin and dst will be process.stdout.
*/
var request = require('request');
var req= request.post('http://localhost:8000');
process.stdin.pipe(req).pipe(process.stdout);