soy nuevo en NodeJS, estoy intentando hacer una peticion POST, pero cada vez que lo intento me devuelve un error eterno Axios. Este es el error que me devuelve y atrapo en el catch de mi petición POST que ahora veréis debajo:
Error: connect ECONNREFUSED 127.0.0.1:443
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 443,
config: {
url: 'url?client_id=xxxxxxxxxxxx&client_secret=xxxxxxxxxxxxxxx&grant_type=xxxxxxxxxxxxxxx',
method: 'post',
data: '{"params":{"client_id":"xxxxxxxxxxxxx","client_secret":"xxxxxxxxxxxxxx"}',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json;charset=utf-8',
'User-Agent': 'axios/0.21.0',
'Content-Length': 115
},
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 0,
adapter: [Function: httpAdapter],
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
validateStatus: [Function: validateStatus]
},
request: Writable {
_writableState: WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: true,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: true,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
afterWriteTickInfo: null,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: false,
errorEmitted: false,
emitClose: true,
autoDestroy: false,
bufferedRequestCount: 0,
corkedRequestsFree: [Object]
},
writable: true,
_events: [Object: null prototype] {
response: [Function: handleResponse],
error: [Function: handleRequestError]
},
_eventsCount: 2,
_maxListeners: undefined,
_options: {
maxRedirects: 21,
maxBodyLength: 10485760,
protocol: 'https:',
path: 'url?client_id=xxxxxxxxxxxxxx&client_secret=xxxxxxxxxxx&grant_type=xxxxxxxxxxx',
method: 'POST',
headers: [Object],
agent: undefined,
agents: [Object],
auth: undefined,
hostname: null,
port: null,
nativeProtocols: [Object],
pathname: 'url',
search: '?client_id=xxxxxxxx&client_secret=xxxxxxxxxxxx&grant_type=xxxxxxxxxx'
},
_ended: false,
_ending: true,
_redirectCount: 0,
_redirects: [],
_requestBodyLength: 115,
_requestBodyBuffers: [ [Object] ],
_onNativeResponse: [Function],
_currentRequest: ClientRequest {
_events: [Object: null prototype],
_eventsCount: 7,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: null,
_hasBody: true,
_trailer: '',
finished: false,
_headerSent: true,
socket: [TLSSocket],
connection: [TLSSocket],
_header: 'POST url?client_id=xxxxxxx&client_secret=xxxxxxxx&grant_type=client_credentials HTTP/1.1\r\n' +
'Accept: application/json, text/plain, */*\r\n' +
'Content-Type: application/json;charset=utf-8\r\n' +
'User-Agent: axios/0.21.0\r\n' +
'Content-Length: 115\r\n' +
'Host: localhost\r\n' +
'Connection: close\r\n' +
'\r\n',
_onPendingData: [Function: noopPendingOutput],
agent: [Agent],
socketPath: undefined,
method: 'POST',
insecureHTTPParser: undefined,
path: 'url?client_id=xxxxxxxxxxx&client_secret=xxxxxxxxxx&grant_type=xxxxxxxxxxxx',
_ended: false,
res: null,
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
_redirectable: [Circular],
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype]
},
_currentUrl: 'url?client_id=xxxxxxxxx&client_secret=xxxxxxxxxx&grant_type=xxxxxxxxxxx',
[Symbol(kCapture)]: false
},
response: undefined,
isAxiosError: true,
toJSON: [Function: toJSON]
}
Aquí os dejo mi petición post:
const token = async() => {
axios.post("url?client_id=xxxxxxxxxxxx&client_secret=xxxxxxxxxxxxxxxx&grant_type=xxxxxxxxxxxxx", {
params: {
client_id: 'xxxxxxxxxxxxxx',
client_secret: 'xxxxxxxxxxxx',
grant_type: 'xxxxxxxxxxxxxx'
}
})
.then(res => {
console.log(res);
})
.catch(err => {
console.log(err);
})
};
Pretendo simular la misma petición que realizo a través de Postman y si me funciona:
Únicamente inserto los params a través de postman, los 7 headers que aparecen en la imagen son los autogenerados por postman.
¿Alguien ve la solución al problema? Muchas gracias de antemano