【问题标题】:Why Axios is timing out even when the request is tested in postman?为什么即使在邮递员中测试了请求,Axios 也会超时?
【发布时间】:2021-05-05 13:45:38
【问题描述】:

我正在尝试使用带有 express/node js 的 axios 为我的应用程序配置一个请求。

下面是使用邮递员应用程序生成的代码 sn-p,在我尝试创建自己的表单等几种变体之前,总是相同的结尾。

const express = require('express')
const axios = require('axios')
var qs = require('qs');

var data = qs.stringify({
'grant_type': 'client_credentials',
'client_id': 'myclientid',
'client_secret': 'myclientsecret',
'scope': 'myscope' 
});
var config = {
  method: 'post',
  url: 'https://myurl/token',
  headers: { 
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  data : data
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});

我总是收到这些错误:

Error: connect ETIMEDOUT IPADDRESS:443
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1128:14) {
  errno: 'ETIMEDOUT',
  code: 'ETIMEDOUT',
  syscall: 'connect',
  address: 'IPA ADDRESS',
  port: 443,

相同的代码 sn-p 在 Postman 中正常工作,我正在接收令牌,所以我不确定我在哪里做错了。

有人吗?

谢谢!

【问题讨论】:

    标签: javascript node.js api express axios


    【解决方案1】:

    好的,我想通了。这个问题是我公司的代理设置引起的,必须使用axios的代理才能正确解析地址。

    【讨论】:

    • 您能提供更多有关此的信息吗?答案还不够。
    猜你喜欢
    • 1970-01-01
    • 2020-06-19
    • 1970-01-01
    • 2018-09-15
    • 2019-05-09
    • 2023-01-20
    • 1970-01-01
    • 2018-07-29
    • 2021-11-22
    相关资源
    最近更新 更多