我的代码在我的本地计算机上运行正常,因为我在etc.hosts文件中添加了一个条目来进行DNS转换。但是当我把它放在我的云供应商那一刻它没有为getaddrinfo ENOTFOUND.can任何人帮我解决这个问题。这不是其他问题的重复。另一个使用https.get,但我使用post方法和npm库“request”
request = require('request'),
var headers = {
'Authorization': 'Basic MTk3Y2RkY2UwYTBjNDA1NGIyN6MGQyOGRiOWYtOGUwYS00M2ExLWEyMzEtYWY4NTgzZTgyMzk3',
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
};
var dataString = 'grant_type=authorization_code&code=' + req.query.code + '&redirect_uri=' + callbackurl + '';
var options = {
uri: 'https://my.url.com/oauth2/v1/token',
method: 'POST',
headers: headers,
body: dataString,
family: 4
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
var jsonObj = JSON.parse(body);
for (var myKey in jsonObj) {
var value = jsonObj[myKey];
console
.log("key:" + myKey + ", value:" + value);
if (myKey === 'access_token') {
req.session.accesstoken = value;
console
.log('Setting Access Token into session-' + req.session.accesstoken);
}
}
res.render('index.jade');
} else {
console.error(error);
// console.log(response);
res
.render(
'error', {
'title': 'Authorization error',
'message': 'Error occured during authorization. Please check with your identity service provider'
});
}
}
request(options, callback);
我的日志说
2017-07-26T03:06:30.701992+00:00 OrderManagement[web.2]: Express server listening on port 8080
2017-07-26T03:06:32.707668+00:00 OrderManagement[web.2]: #033[90mHEAD / #033[32m200 #033[90m449ms - 318b#033[0m
2017-07-26T03:06:40.022051+00:00 OrderManagement[web.2]: #033[90mGET / #033[32m200 #033[90m50ms - 318b#033[0m
2017-07-26T03:07:07.694066+00:00 OrderManagement[web.2]: #033[90mGET / #033[32m200 #033[90m42ms - 318b#033[0m
2017-07-26T03:07:12.098025+00:00 OrderManagement[web.2]: #033[90mGET / #033[32m200 #033[90m34ms - 318b#033[0m
2017-07-26T03:07:12.226770+00:00 OrderManagement[web.2]: #033[90mGET /stylesheets/style.css #033[32m200 #033[90m10ms - 117b#033[0m
2017-07-26T03:07:14.343551+00:00 OrderManagement[web.2]: #033[90mGET /auth #033[36m302 #033[90m13ms - 560b#033[0m
2017-07-26T03:07:18.359009+00:00 OrderManagement[web.2]: #033[90mGET / #033[32m200 #033[90m40ms - 318b#033[0m
2017-07-26T03:07:22.938992+00:00 OrderManagement[web.2]: inside callback
2017-07-26T03:07:22.939374+00:00 OrderManagement[web.2]: Authorization code is - AQIDBAW95eO2ziGpFSfOEzEd9tMzYpYpGV7zL3-4arEwhe-JWEU32lG0BKQNdnrUE1EJRFWW4kwnunMQi84To7_E8u3mMTEgRU5DUllQVElPTl9LRVkxNCB7djF9NCA=
2017-07-26T03:07:22.939664+00:00 OrderManagement[web.2]: Get Access Token and Validate it. If valid then render the order page or show error page
2017-07-26T03:07:23.009412+00:00 OrderManagement[web.2]: { Error: getaddrinfo ENOTFOUND my.url.com:8943
2017-07-26T03:07:23.009756+00:00 OrderManagement[web.2]: at errnoException (dns.js:28:10)
2017-07-26T03:07:23.010029+00:00 OrderManagement[web.2]: at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
2017-07-26T03:07:23.010332+00:00 OrderManagement[web.2]: code: 'ENOTFOUND',
2017-07-26T03:07:23.010613+00:00 OrderManagement[web.2]: errno: 'ENOTFOUND',
2017-07-26T03:07:23.010870+00:00 OrderManagement[web.2]: syscall: 'getaddrinfo',
2017-07-26T03:07:23.011126+00:00 OrderManagement[web.2]: hostname: 'my.url.com',
2017-07-26T03:07:23.011425+00:00 OrderManagement[web.2]: host: 'my.url.com',
2017-07-26T03:07:23.011680+00:00 OrderManagement[web.2]: port: '8943' }
2017-07-26T03:07:23.054720+00:00 OrderManagement[web.2]: #033[90mGET /callback?code=AQIDBAW95eO2ziGpFSfOEzEd9tMzYpYpGV7zL3-4arEwhe-JWEU32lG0BKQNdnrUE1EJRFWW4kwnunMQi84To7_E8u3mMTEgRU5DUllQVElPTl9LRVkxNCB7djF9NCA=&state=23456 #033[32m200 #033[90m123ms - 316b#033[0m
2017-07-26T03:07:23.204151+00:00 OrderManagement[web.2]: #033[90mGET /stylesheets/style.css #033[36m304 #033[90m2ms#033[0m
2017-07-26T03:07:38.207878+00:00 OrderManagement[web.2]: #033[90mGET / #033[32m200 #033[90m36ms - 318b#033[0m
我没有对云提供商的操作系统级访问权限。因此,当我在云提供商中托管它时,我无法添加相同的DNS条目。我想要点击的URI是一个公共URI。