【问题标题】:Sending NodeJs Axios requests via Fiddler通过 Fiddler 发送 NodeJs Axios 请求
【发布时间】:2018-11-08 23:45:59
【问题描述】:

我正在使用 Windows + Visual Studio 代码来开发 Node JS API。我正在使用 Axios 从 NodeJs 向第三方 API 提交休息请求。

我想检查从我的节点服务器通过 Fiddler 发送到第三方后端的数据包,但是我一直很难让 Axios 通过 127.0.0.1 端口 8888 进行代理。

理想情况下,它会是一个简单的全局变量来设置打开/关闭代理。我尝试过的是:

axios.defaults.proxy = { host: "127.0.0.1", port:8888}

axios.defaults.proxy = { host: "127.0.0.1", port:8888, protocol: "http"}

axios.post(url: <api>, {post:data}, {proxy: {host: "127.0.0.1", "8888"} });

以及上述的许多不同变体。当代理开启时,它不会完成请求。

【问题讨论】:

    标签: node.js axios fiddler


    【解决方案1】:

    您尝试访问的服务器是否使用https?这是axios 的问题,他们似乎无法解决。

    允许您通过 Fiddler 进行代理的解决方法是使用 HTTPS-over-HTTP 隧道。 Jan Molak 写了this nice article 关于通过http 代理向https 服务器发送请求的场景。通过 Fiddler 运行请求时,以下代码对我有用:

    const axios = require('axios');
    const tunnel = require('tunnel');
    
    const axiosInstance = axios.create({
      httpsAgent = tunnel.httpsOverHttp({
        host: '127.0.0.1',
        port: 8888,
      }),
      proxy: false,
    });
    
    axiosInstance.post(/* ... */);
    

    【讨论】:

    • 无法说出我在寻找解决方案多长时间...谢谢!
    猜你喜欢
    • 1970-01-01
    • 2019-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-13
    • 1970-01-01
    • 1970-01-01
    • 2018-05-04
    相关资源
    最近更新 更多