windows - 为什么我无法在 Windows 10 上读取 deno 代理环境变量?

标签 windows proxy deno

我在 Windows 10 上阅读了 deno 手册,其中说您需要设置环境变量 HTTPS_PROXY 以便 fetch() 将使用代理。

我是这样做的

Deno.env.set('HTTP_PROXY', 'https://138.68.60.8:3128/');
Deno.env.set('HTTPS_PROXY', 'https://138.68.60.8:3128/');

然而,在没有代理的情况下,抓取仍然抓取。相反,如果我在 Windows 系统设置中设置代理,提取将使用它。这并没有解决问题,因为我正在尝试滚动代理列表。

最佳答案

查看 Deno 源代码,他们自己的测试使用了我在文档中找不到的不同方法:

// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.

const client = Deno.createHttpClient({
  proxy: {
    url: "http://localhost:4555",
    basicAuth: { username: "username", password: "password" },
  },
});

const res = await fetch(
  "http://localhost:4545/045_mod.ts",
  { client },
);
console.log(`Response http: ${await res.text()}`);

client.close();

对于您的特定用例,我会设置一个 http 客户端:

const client = Deno.createHttpClient({
  proxy: {
    url: "https://138.68.60.8:3128",
  },
});

然后在您的获取请求中使用该客户端:

fetch("https://example.com", { client });

关于windows - 为什么我无法在 Windows 10 上读取 deno 代理环境变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66416535/

相关文章:

windows - Windows 批处理中的 LastIndexOf

typescript - Deno:VSCode typescript 不知道 ES6

node.js - 使用 OpenCV 的 deno 模板匹配没有给出结果

excel - 通过具有默认凭据的代理从 Excel 发出 http 获取请求

firebase - 在 Deno 中使用 firebase-admin 的可能方法

windows - 将 IRP 读/写数据包从 UMDF 驱动程序发送到内核模式驱动程序

python - 在 PyCharm 之外运行 PyCharm 项目

asp.net - 如何使 ODP.NET 4.0(64 位)在 64 位计算机 Windows 7 上运行?

java - 尝试用 Java 发送请求时出现错误 407

通过 HTTP 代理进行 iOS XMPP 聊天