【问题标题】:CURL --resolve in node.js axiosCURL --resolve 在 node.js axios
【发布时间】:2020-07-22 12:14:03
【问题描述】:

纯 CURL 中的示例请求:

curl https://www.example.com --resolve www.example.com:443:127.0.0.1

Node.js 代码(缺少“解析”功能):

const axios = require('axios');
axios({
  method: 'GET',
  url: 'https://www.example.com'
}).then((response) => {
  console.log(response);
}).catch((error) => {
  console.error(error);
});

如何将 resolve 选项传递给 Node.js Axios?我在他们的readme 中找不到任何相关信息。

它甚至有这样的功能吗?如果不是,NPM 包的作用是什么?

【问题讨论】:

    标签: node.js curl axios resolve


    【解决方案1】:

    Axios 没有内置此功能。

    但是您可以尝试在标头中传递主机?

    我需要 https 来阻止 ssl 问题。

    const axios = require('axios')
    const https = require('https')
    
    const handler = async () => {
        const response = await axios.get('https://www.example.com', {
            headers: { Host: '127.0.0.1:443' },
            httpsAgent: new https.Agent({
                rejectUnauthorized: false,
            }),
        })
    
        console.log(response)
    }
    
    handler()
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-07
      • 2021-01-01
      • 2016-10-31
      • 2020-12-23
      • 2017-06-30
      • 2022-01-23
      • 2021-10-01
      相关资源
      最近更新 更多