Nodejs request 模块和 https 模块请求同一个文件 uri 时, request 模块请求失败 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
rateltalk

Nodejs request 模块和 https 模块请求同一个文件 uri 时, request 模块请求失败

  •  
  •   rateltalk Dec 15, 2022 5291 views
    This topic created in 1231 days ago, the information mentioned may be changed or developed.

    神奇的是,使用 https 模块时可以正常访问 uri 并保存在本地,但是使用 request 模块时请求都发不出去,百思不得其解,报错信息如下:

    Error: tunneling socket could not be established, cause=getaddrinfo ENOTFOUND 7890 at ClientRequest.onError (D:\www\BWK_Spider\node_modules\tunnel-agent\index.js:177:17) at Object.onceWrapper (node:events:642:26) at ClientRequest.emit (node:events:527:28) at Socket.socketErrorListener (node:_http_client:454:9) at Socket.emit (node:events:527:28) at emitErrorNT (node:internal/streams/destroy:157:8) at emitErrorCloseNT (node:internal/streams/destroy:122:3) at processTicksAndRejections (node:internal/process/task_queues:83:21) { code: 'ECONNRESET' } 

    request 模块代码:

    const request = require("request"); const fs = require("fs"); request("https://xxx.xx.xx/20_C12100030.pdf") .pipe(fs.createWriteStream("C:\\Users\\444\\Desktop\\20_C12100030.pdf")) .on("close", function (err) { console.log("下载完成"); console.log(err); }) .on("error", function (err) { console.log(err); }); 

    https 模块代码

    const https = require("https"); const file = fs.createWriteStream( "C:\\Users\\444\\Desktop\\20_C12100030.pdf" ); https .get("https://xxx.xx.xx/20_C12100030.pdf", (response) => { console.log("请求成功"); response.pipe(file); // after download completed close filestream file.on("finish", () => { file.close(); console.log("Download Completed"); }); }) .on("error", (err) => { console.log("Error: ", err.message); }); 

    有遇到这种情况的吗?网上搜索都说是 npm 代理导致的,但实际不是,否则使用 https 模块时也应该是请求发不出去才对。

    4 replies    2022-12-16 15:07:37 +08:00
    okakuyang
        1
    okakuyang  
       Dec 15, 2022
    7890 这个显然是你的梯子代理端口
    Pastsong
        2
    Pastsong  
       Dec 15, 2022
    request 读了你的 HTTP_PROXY/HTTPS_PROXY 环境变量
    rateltalk
        3
    rateltalk  
    OP
       Dec 16, 2022
    @okakuyang
    我梯子可正常访问呐
    Opportunity
        4
    Opportunity  
       Dec 16, 2022
    https 模块又不会自动走代理
    About     Help     Advertise     Blog     API     FAQ     Solana     4920 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 41ms UTC 09:21 PVG 17:21 LAX 02:21 JFK 05:21
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86