代码:
var rp = require('request-promise');
var options = {
method: 'POST',
uri: 'http://c663fe13.ngrok.io/ap/lighton',
body: {"color": 'white'},
json: true // Automatically stringifies the body to JSON
};
rp(options)
.then(function (parsedBody) {
// POST succeeded...+
console.log("parsedBody", parsedBody);
})
.catch(function (err) {
// POST failed...
console.log("err", err);
});
但这给了我以下错误:
{ RequestError: Error: getaddrinfo EAI_AGAIN c663fe13.ngrok.io:80 at new RequestError (/srv/node_modules/request-promise-core/lib/errors.js:14:15) at Request.plumbing.callback (/srv/node_modules /request-promise-core/lib/plumbing.js:87:29) 在 Request.RP$callback [as _callback] (/srv/node_modules/request-promise-core/lib/plumbing.js:46:31)
. . .
名称:'RequestError',消息:'错误:getaddrinfo EAI_AGAIN c663fe13.ngrok.io:80',
原因:{错误:getaddrinfoEAI_AGAIN c663fe13.ngrok.io:80 at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67 :26) errno:'EAI_AGAIN',代码:'EAI_AGAIN',系统调用:'getaddrinfo',主机名:'c663fe13.ngrok.io',主机:'c663fe13.ngrok.io',端口:80},
我尝试用邮递员调用该 API,它工作正常。