Node 经代理请求 Telegram Bot Api 数据

2016/07/25 | 1分钟阅读 | 更新于 2016/07/25

[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);
  }
});

© 2026 香蕉引擎故障报告

🌱 Powered by Hugo with theme Dream.

关于

要怎么介绍自己呢,🤔。

很早以前是作为 Web 前端在学习的,但是工作第一年就成为了全干工程师。喜欢尝试各种东西,什么都会一点。

一直很喜欢 Ebiten 游戏引擎 ,特别简洁,用它做过一些小东西,可以查看这个分类 。另外特别推荐这个木鱼 ,是一个相对完整的小玩意儿,包含手搓的一个简单的 UI 框架;支持鼠标和键盘操作;有多语言和主题切换功能;同时支持 Web 端和客户端。它的源代码在 bin16/wooden-fish

主题

网站基于 Hugo,当前使用的是 hugo-theme-dream 主题的修改版 ,根据我的需要,做了一些对 PaperMod 的兼容。

我自己也写过主题 ,但是没有别人写的好看。

正在从我的笔记中往外搬运内容

等待更新:

  • 从《锈湖》中学了些什么东西
  • 我拿 React 写解谜游戏的经过
  • 基于 Pocketbase 的 Pocket Memos
  • 数独!