简体   繁体   中英

connect ETIMEDOUT Node.js

I am using a create hook in my Auth0 Delegated Administration Extension .

I am getting this error when trigger the create hook:

Error: connect ETIMEDOUT xxx.xxx.xxx.xxx:8081
    at Object.exports._errnoException (util.js:1020:11)
    at exports._exceptionWithHostPort (util.js:1043:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)

Create Hook function is:

function(ctx, callback) {

    var request = require('request');

    // Perform any asynchronous actions
    var API_URL = "https://example.com:8081/api/saveData";

    var empFirstName = 'Jhone';
    var empId = '123';

    request.post({
            url: API_URL,
            json: {
                firstName: empFirstName,
                userId: empId
            }
        },
        function(error, response, body) {
            if (error) {
                ctx.log('Create failed to '+API_URL+':', error);
                return callback(new Error('Something went wrong. Please try again.'));
            }
            ctx.log('Create successful!  Server responded with:', body);
            return callback(null, {
                /*some data here*/
            });
        });
}

I have tried with postman and it works as expected. But with the create hook, I am getting above error.

What could be the issue?

It seems your endpoint is unavailable or not responding.

Are you sure this endpoint handle content-type: application/json ? otherwise try to send it as x-form-www-urlencoded.

request.post({
    url: MY_URL,
    form: {
        firstName: empFirstName,
        userId: empId
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM