Why Axios is timing out even when the request is tested in postman?

Viewed 792

I am trying to configure one request for my app using axios with express/node js.

Below is the code snippet generated with postman app, ofc before i have tried several variations with creating my own form etc, always same ending.

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);
});

I am always receiving those errors:

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,

Same code snippet is working correctly in Postman and I am receiving token so I am not sure where I am doing the mistake.

Anyone?

Thanks!

1 Answers

Ok, I figured it out. This problem was caused by proxy settings in my company, had to use proxy agent for axios to resolve address properly.

Related