Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Firebase的云函数错误:getaddrinfo ENOTFOUND_Javascript_Node.js_Firebase_Google Cloud Functions - Fatal编程技术网

Javascript Firebase的云函数错误:getaddrinfo ENOTFOUND

Javascript Firebase的云函数错误:getaddrinfo ENOTFOUND,javascript,node.js,firebase,google-cloud-functions,Javascript,Node.js,Firebase,Google Cloud Functions,我有请求函数和尝试集成Firebase的宽度云函数 var http = require("https"); function addUserToMailchimpList(email) { var options = { method: 'POST', url: 'https://usxx.api.mailchimp.com/3.0/lists/xxxxxxx/members/', headers: { 'content-type':

我有请求函数和尝试集成Firebase的宽度云函数

var http = require("https");

    function addUserToMailchimpList(email) {
    var options = { method: 'POST',
      url: 'https://usxx.api.mailchimp.com/3.0/lists/xxxxxxx/members/',
      headers: 
       { 'content-type': 'application/json',
         'user' : 'anystring:xxxxxxxxxxxxxxxxxxxxxxx'
       },

      body: 
       { email_address: email,
         status: 'subscribed',
       },
      json: true };

    request(options, function (error, response, body) {
      if (error) throw new Error(error);
      console.log(body);
      console.log(error);
      console.loh(response);
    });

}
然后我尝试部署这个函数

exports.sendWelcomeEmail = functions.auth.user().onCreate(event => {
  const user = event.data; // The Firebase user.
  const email = user.email; // The email of the user.
  const displayName = user.displayName; // The display name of the user.

  return addUserToMailchimpList(email);
});
但在firebase函数日志中,我发现了错误:

Error: Error: getaddrinfo ENOTFOUND usxx.api.mailchimp.com usxx.api.mailchimp.com:443
我做错了什么?你不相信吗

我尝试使用的另一种方法也是一样的错误

function addUserToMailchimpList(email) {

  var options = {
    "method": "POST",
    "hostname": "usxx.api.mailchimp.com",
    "port": null,
    "path": "/3.0/lists/xxxxx/members/",
    "headers": {
      "content-type": "application/json",
      "user": "anystring:xxxxxxxxxx",
    }
  };

  var req = http.request(options, function (res) {
    var chunks = [];

    res.on("data", function (chunk) {
      chunks.push(chunk);
    });

    res.on("end", function () {
      var body = Buffer.concat(chunks);
      console.log(body.toString());
    });
  });

  req.write(JSON.stringify({ email_address: email,
    status: 'subscribed',
    merge_fields: { FNAME: 'xxx', LNAME: 'xxx' } }));
  req.end();

}

建议在从Firebase云功能执行API请求之前,您需要先启用计费。

usxx.API.mailchimp.com
无法解析为IP号。主机名无效、DNS不知道、某些防病毒/防火墙软件正在阻止查找等。我是从localhost部署的,但功能是从Firebase执行的也许您不允许从Firebase创建网络连接?建议为了发出外部API请求,您需要启用计费。是的,这似乎就是我出错的原因。谢谢你可以加上这个作为答案,所以我会接受。