[TOC]
npm / request
Request is designed to be the simplest way possible to make http calls. It supports HTTPS and follows redirects by default.
npm install request
var request = require("request");
request("http://www.google.com", function (err, res, body) {
if (!err && res.statusCode == 200) {
console.log(body);
}
});
From: https://github.com/request/request
npm / https-proxy-agent
This module provides an http.Agent implementation that connects to a specified HTTP or HTTPS proxy server, and can be used with the built-in https module.
Specifically, this Agent implementation connects to an intermediary “proxy” server and issues the CONNECT HTTP method, which tells the proxy to open a direct TCP connection to the destination server.
Since this agent implements the CONNECT HTTP method, it also works with other protocols that use this method when connecting over proxies (i.e. WebSockets). See the “Examples” section below for more.
npm install https-proxy-agent
var HttpsProxyAgent = require("https-proxy-agent");
var proxy = "http://127.0.0.1:1090/";
var opts = {
protocal: "https://",
host: "google.com",
path: "/",
};
var agent = new HttpsProxyAgent(proxy);
// opts.agent = agent; /* Important! */
var req = https.request(opts, function (res) {
console.log("statusCode: ", res.statusCode);
res.on("data", function (d) {
// console.log( d );
process.stdout.write(d);
});
});
req.end();
req.on("error", function (e) {
console.log(e);
});
From: https://www.npmjs.com/package/https-proxy-agent
Now …
var request = require("request");
var HttpsProxyAgent = require("https-proxy-agent");
var token = "******"; /* Here is your token. */
var method = "getMe";
var proxy = "http://127.0.0.1:1090/";
var agent = new HttpsProxyAgent(proxy);
var opts = {
uri: `https://api.telegram.org/bot${token}/${method}`,
agent: agent,
};
request(opts, (err, res, body) => {
if (!err && res.statusCode == 200) {
console.log(body);
}
});