因此,在使用core-https对webstie执行Get请求时,通过使用以下代码,我正在使用代理进行此获取请求:
const { HttpsProxyAgent } = require("https-proxy-agent");
const proxy = new HttpsProxyAgent(`http://user:pass@host:port`);
https.get("https://www.google.com/",
{ agent: proxy },
(res) => {
var body = "";
res.on("data", function (chunk) {
body += chunk;
// console.log(body)
});
res.on("end", function () {
}
);
})因此,有时代理将无效或过期,甚至使用本地主机使用fiddler或Charles进行调试。
const { HttpsProxyAgent } = require("https-proxy-agent");
const proxy = new HttpsProxyAgent(`http://127.0.0.1:8888`); // For Debugging
https.get("https://www.google.com/",
{ agent: proxy },
(res) => {
var body = "";
res.on("data", function (chunk) {
body += chunk;
// console.log(body)
});
res.on("end", function () {
}
);
})如果我忘记打开代理调试器,也会导致错误。
我试过这样做:
res.on("error" , function(e){
console.log("an error have been occurred ")
})但似乎什么都起不到作用
发布于 2021-06-03 14:33:29
所以我找到了答案,就像这样
https.get(
"https://www.google.com/",
{ agent: proxy },
(res) => {
var body = "";
res.on("data", function (chunk) {
body += chunk;
});
res.on("end", function () {
// console.log(body)
})
.on('error', function (e) {
console.error("error");
}).end();https://stackoverflow.com/questions/67821726
复制相似问题