• 这个我还没有想清楚原理是什么,但是可以访问…
  • app.js 端口号 3000 node app.js
    var express = require('express');
    const path = require('path');
    const axios = require("axios");
    const HttpsProxyAgent = require("https-proxy-agent");
    var app = express();
    
    app.set('port', 3000);
    
    app.get('/', function(req, res){
        const httpsAgent = new HttpsProxyAgent(`http://127.0.0.1:4000`);
        const instance = axios.create({
            proxy:false,
            httpsAgent
        })
        instance('http://127.0.0.1:4000/')
            .then(function(res) {
                console.log(res);
            })
    });
    
    app.listen(app.get('port'), function(){
        console.log( 'Express started on http://localhost:' + 
            app.get('port') + '; press Ctrl-C to terminate.' );
    });
    
  • test.js 4000 node test.js
    var express = require('express');
    const path = require('path')
    var app = express();
    
    app.set('port', 4000);
    
    app.get('/', function(req, res){
        res.end('成功啦');
    });
    
    app.listen(app.get('port'), function(){
        console.log( 'Express started on http://localhost:' + 
            app.get('port') + '; press Ctrl-C to terminate.' );
    });
    
  • 结果
    在这里插入图片描述
Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐