Node.js Web App API调用导致ENOTFOUND

我创build了一个部署在Heroku上的Web应用程序,以及一个单独的节点服务器,可以对应用程序进行API调用。 当服务器发出请求时,我得到一个ENOTFOUND错误。

服务器请求:

var gameOptions, body, gameReq; var currentOptions, currReq; // Create New Game -------------------------------------------------- // I have also tried hostname: "https://myChessApp.herokuapp.com/api" gameOptions = { hostname: 'myChessApp.herokuapp.com/api', path: '/games', headers: {'Content-Type' : 'application/json'}, method: 'POST' }; body = { fen :"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", pgn :"", createdAt : Date.now(), lastMoveAt : Date.now() } gameReq = HTTPS.request(gameOptions, function(res) { if(res.statusCode == 202) { console.log('Game Created: ' + res.text); } else { console.log('Bad status code: ' + res.statusCode); } }); gameReq.on('error', function(err) { console.log('error creating game ' + JSON.stringify(err)); console.error(err.stack); }); gameReq.on('timeout', function(err) { console.log('timeout creating game ' + JSON.stringify(err)); }); gameReq.end(JSON.stringify(body)); 

错误:

 error creating game {"code":"ENOTFOUND","errno":"ENOTFOUND","syscall":"getaddrinfo","hostname":"myChessApp.herokuapp.com/api","host":"myChessApp.herokuapp.com/api","port":443} Error: getaddrinfo ENOTFOUND myChessApp.herokuapp.com/api myChessApp.herokuapp.com/api:443 at errnoException (dns.js:28:10) at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26) 

不过,我已经尝试使用cURL成功发布相同的JSON正文,因此可以在此实例中find地址:

 curl -X POST -H "Content-Type: application/json" -d '{ "fen":"fen", "pgn":"", "createdAt":1, "lastMoveAt":2 }' "https://myChessApp.herokuapp.com/api/games" 

我是否在Node中错误地提出请求? (注意:应用程序URL已被更改为匿名)

gameOptions这个

 gameOptions = { hostname: 'myChessApp.herokuapp.com', path: '/api/games', headers: {'Content-Type' : 'application/json'}, method: 'POST' };