在GET请求中调用POST请求时连接ECONNREFUSED 127.0.0.1:443

时间:2019-02-12 13:47:55

标签: javascript node.js http http-post

我不确定我所做的工作是否是正确的实施方式。

这是我尝试过的方法,我正在执行GET请求以从Google提取数据,然后需要通过POST请求将数据发送到我的服务器。

当我发布请求时,出现以下错误:

connect ECONNREFUSED 127.0.0.1:443

NodeJS中的代码

  request({
  url: 'https://people.googleapis.com/v1/people/me?requestMask.includeField=person.photos,person.emailAddresses,person.names',
  auth: {
          'bearer': access_token
        }

  }, function(err, response) {

   if(err)
   {
       res.status(500).send({ error: " Info error", data: null, message: "Error" });
       res.end();
   }
   else
   {
       var res_data  = JSON.parse(response.body);
       var username  = res_data.names[0].displayName;
       var userid    = res_data.names[0].metadata.source.id;
       var data = {name: username,id:userid};

        postToApp(data, (postResponse) => {

          //respond back with the result/error to your API
          console.log(postResponse);
        });
    }
    });

postToApp函数

 function postToApp(data, callback) {

 var options = {
url : 'https://localhost/:3333/saveInfo',
method : 'POST',
body : data,
json : true
};

request(options, function (error, response, body) {
console.log(error + response + body);
if (!error && response.statusCode == 200) {
  console.log(body);
  callback(body) // call the function back with the data you want to process;
} else {
  console.log('Error from server is' + error);
  callback(error) // call the function back with error to process;
}

  });
}

0 个答案:

没有答案