【问题标题】:connect ETIMEDOUT Node.js连接 ETIMEDOUT Node.js
【发布时间】:2018-04-25 19:46:18
【问题描述】:

我在我的Auth0 Delegated Administration Extension 中使用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)

创建Hook函数是:

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

我已尝试使用postman,它按预期工作。但是使用 create 钩子,我遇到了错误。

可能是什么问题?

【问题讨论】:

  • 你的回调是什么样的?
  • 用邮递员试试看有没有响应?
  • @SelloMkantjwa 这甚至没有命中服务器。我添加了控制台登录端点,它从未被打印出来。
  • @NidhinDavid 是的。我试过邮递员,它的工作。
  • 只是为了确认,所以实际失败的调用是对“example.com:8081/api/saveData”的调用,而对同一端点的调用在邮递员中工作正常?

标签: node.js auth0 auth0-delegated-admin


【解决方案1】:

您的端点似乎不可用或没有响应。

您确定此端点处理 content-type: application/json 吗?否则尝试将其作为 x-form-www-urlencoded 发送。

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

【讨论】:

  • 这个也不行
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-02-13
  • 1970-01-01
  • 2022-10-21
  • 1970-01-01
  • 2014-09-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多