URL 배열이 있다고 가정하고 각 URL이 작동하는지 확인하려면 다음 코드를 작성해야합니다. 그러나 배열의 마지막 URL 만 테스트됩니다. 각 URL이 200 응답 코드를 반환하도록하려면 어떻게해야합니까? 분명히하기 위해 내가 테스트하고있는 모든 원격 주소이며 그들은 상당히 크기가 조정 된 PDF를 가리 킵니다.Node.js로 URL 테스트
@ lukas.pukenis의 응답을 기반으로 업데이트되었습니다. 결과는 비슷하지만 실제로 몇 개의 파일 만 검사됩니다.
function check(l) {
console.log(l);
http.get(l, function(res) {
if (res.statusCode != 200) {
console.log(res.statusCode + ' on '+l);
} else {
console.log('success on ' + l);
}
});
}
for (link in fileLinks) {
check(fileLinks[link]);
}
이 코드 출력 : 루프가 L 변수를 var l = fileLinks[link];
그래서 L 배열의 마지막 값의 값이 각각 시간 재기록 때문에
http://somesite.com/somefile1.pdf
http://somesite.com/somefile2.pdf
http://somesite.com/somefile3.pdf
...
all the rest of them
...
http://somesite.com/somefile99.pdf
success on http://somesite.com/somefile1.pdf
success on http://somesite.com/somefile2.pdf
404 on http://somesite.com/somefile5.pdf
success on http://somesite.com/somefile7.pdf
'fileLinks' 배열이면 통해 루프로 사용되는 '.forEach (함수 (항목) {})'대신에 'for'의 기능을 사용하려고 자바 스크립트 객체의 다양한 키. 배열과 함께 사용되는 것은 아닙니다. – Jondlm