我在 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/