forked from devlucky/Kakapo.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_request.js
71 lines (65 loc) · 1.65 KB
/
node_request.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
const querystring = require('querystring');
const http = require('http');
const https = require('https');
const getRequest = () => {
const endpoint = 'https://api.github.com/emojis';
const httpsOptions = {
host: 'api.github.com',
path: '/emojis'
};
const options = {
host: 'personatestuser.org',
path: '/email'
};
// const req = http.request(options, res => {
const req = https.request(options, res => {
console.log(res);
let body = '';
// const req = http.request(endpoint, function(res) {
res.setEncoding('utf8');
res.on('data', chunk => {
body += chunk;
// console.log('data' + chunk);
});
res.on('end', () => {
const json = JSON.parse(body);
// console.log('end', arguments);
console.log('end', json);
});
});
// req.write(data);
req.end();
}
const httpsGet = () => {
https.get('https://api.github.com/emojis', (res) => {
console.log('statusCode: ', res.statusCode);
console.log('headers: ', res.headers);
res.on('data', (d) => {
process.stdout.write(d);
});
}).on('error', (e) => {
console.error(e);
});
};
const postRequest = () => {
const options = {
host: 'closure-compiler.appspot.com',
port: '80',
path: '/compile',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(data)
}
};
const data = querystring.stringify({
'compilation_level': 'ADVANCED_OPTIMIZATIONS',
'output_format': 'json',
'output_info': 'compiled_code',
'warning_level': 'QUIET',
'js_code': codestring
});
}
// getRequest();
httpsGet();