-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebhelper.js
71 lines (65 loc) · 1.95 KB
/
webhelper.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";
let sa = require("superagent");
// let request = require("request");
let timeout = 5 * 1000;
class WebHelper {
static httpGet(url, headers) {
return new Promise(function (resolve, reject) {
sa
.get(url)
.set(headers == null ? {} : headers)
.end(function (err, res) {
if (err) {
reject(err);
return;
}
console.log(JSON.stringify(res.text));
resolve(res.text);
});
});
}
// static httpGet2(url) {
// return new Promise(function (resolve, reject) {
// req.get(url, function (err, response, body) {
// if (err) {
// reject(err);
// return;
// }
// resolve(body);
// });
// });
// }
static httpPost(url, headers, data) {
return new Promise(function (resolve, reject) {
sa
.post(url)
.type('form')
.set(headers == null ? {} : headers)
.send(data)
.timeout(timeout)
.end(function (err, res) {
if (err) {
reject(err);
return;
}
resolve(res.text);
});
});
}
// static httpPost2(url, headers, data) {
// let option = {
// url: url,
// method: "POST",
// json: true,
// headers: headers,
// form: data
// };
// return new Promise((resolve, reject) => {
// request(option, function (error, response, body) {
// console.log(JSON.stringify(response));
// resolve(body);
// });
// });
// }
}
module.exports = WebHelper;