API 요청을 보내려고합니다. 나는 200 응답을 얻지 만 콜백 함수는 끝나는 것을 포함하여 일어나지 않는다. 여기에 관련 섹션이 있으며, 나머지 Express 서버가 있으며 서버가 실행 중입니다.https 응답의 콜백 함수가 nodejs에서 실행되지 않음
var https = require("https");
https.get("https://tfe-opendata.com/api/v1/stops", function(res){
console.log("Response: ", res.statusCode);
console.log("Res: " + res);
}).on('data', function(data) {
console.log('blah');
console.log("data: " + data);
process.stdout.write(data);
}).on('error', function(error) {
console.error('Error ' + error);
}).on('end', function(){
console.log("End.");
});
그것은 단지 JSON을 반환해야하고, 당신이 address에 가면 당신은 데이터와 URL이 유효한지 확인할 수 있습니다. 첫 번째 콜백 이후의 인쇄물이 없습니다.
편집 : 나는 원래가 작동하지 않은 이유는 아직 모른다 전체 https.request 방법을
var options = {
host: 'tfe-opendata.com',
path: '/api/v1/stops',
method: 'GET'
}
var httpreq = https.request(options, function(response) {
response.on('data', function(chunk) {
console.log("data " + chunk);
});
});
httpreq.on('error', function(e) {
console.log('error: ' + e);
});
httpreq.end();
를 사용하는 경우 작동합니다.
을 당신이 경로를 사용할 수 있는지 정말 모르겠습니다 domin'('https://tfe-opendata.com/api/v1/stops')의 형식으로, 대신에'('/ api/v1/stops')' –
문서에서 확인할 수 있습니다. http://nodejs.org/api/https.html#https_https_get_options_callback – michaelAdam