2022-08-25 20:57:25 +03:00
|
|
|
import https from "https";
|
|
|
|
import http from "http";
|
|
|
|
|
2022-08-26 22:33:54 +03:00
|
|
|
export function httpsRequest(url, params) {
|
2022-08-25 20:57:25 +03:00
|
|
|
return new Promise(function (resolve, reject) {
|
2022-08-26 22:33:54 +03:00
|
|
|
var request = https.request(url, params, function (response) {
|
2022-08-27 12:38:32 +03:00
|
|
|
var data = [];
|
2022-08-25 20:57:25 +03:00
|
|
|
|
|
|
|
response.on("data", (chunk) => {
|
2022-08-27 12:38:32 +03:00
|
|
|
data.push(chunk);
|
2022-08-25 20:57:25 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
response.on("end", () => {
|
2022-08-27 12:38:32 +03:00
|
|
|
resolve([response.statusCode, response.headers["content-type"], Buffer.concat(data)]);
|
2022-08-25 20:57:25 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
request.on("error", (error) => {
|
|
|
|
reject([500, error]);
|
|
|
|
});
|
|
|
|
|
|
|
|
request.end();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-08-26 22:33:54 +03:00
|
|
|
export function httpRequest(url, params) {
|
2022-08-25 20:57:25 +03:00
|
|
|
return new Promise(function (resolve, reject) {
|
2022-08-26 22:33:54 +03:00
|
|
|
var request = http.request(url, params, function (response) {
|
2022-08-27 12:38:32 +03:00
|
|
|
var data = [];
|
2022-08-25 20:57:25 +03:00
|
|
|
|
|
|
|
response.on("data", (chunk) => {
|
2022-08-27 12:38:32 +03:00
|
|
|
data.push(chunk);
|
2022-08-25 20:57:25 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
response.on("end", () => {
|
2022-08-27 12:38:32 +03:00
|
|
|
resolve([response.statusCode, response.headers["content-type"], Buffer.concat(data)]);
|
2022-08-25 20:57:25 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
request.on("error", (error) => {
|
|
|
|
reject([500, error]);
|
|
|
|
});
|
|
|
|
|
|
|
|
request.end();
|
|
|
|
});
|
|
|
|
}
|