나는 프록시를 사용하고 있습니다. 노드 스크립트로 storage.googleapis.com
에서 zip
파일을 다운로드하려고합니다.https 모듈로 프록시 요청을 할 수 없습니다.
나는 제대로 환경 나는에서 오전 프로세스에 대한 변수와 명령으로 curl
작품과 파일 다운로드 등의 HTTPS_PROXY
및 HTTP_PROXY
세트가 있습니다.
curl -O https://storage.googleapis.com/chromium-browser-snapshots/Mac/515411/chrome-mac.zip
이것은 노드 스크립트입니다. 노드에서 이것을 실행하면 상태 코드가 407
을 반환합니다. 왜? 프록시 에이전트가 설정되어 있고 curl
과 완벽하게 작동합니다.
const URL = require('url')
const ProxyAgent = require('https-proxy-agent');
const getProxyForUrl = require('proxy-from-env').getProxyForUrl;
const https = require('https')
const url = 'https://storage.googleapis.com/chromium-browser-snapshots/Mac/515411/chrome-mac.zip'
function requestOptions(url, method = 'GET') {
/** @type {Object} */
const result = URL.parse(url);
result.method = method;
const proxyURL = getProxyForUrl(url);
if (proxyURL) {
/** @type {Object} */
const parsedProxyURL = URL.parse(proxyURL);
parsedProxyURL.secureProxy = parsedProxyURL.protocol === 'https:';
result.agent = new ProxyAgent(parsedProxyURL);
}
console.log(result)
return result;
}
https.get(requestOptions(url), response => {
console.log(response.statusCode)
})
'407'은'프록시 인증 Required'이지만, I는'username'를 통과 할 때'난'로컬 발행자를 얻을 수없는 얻을 프록시 전역에 password' 'secureProxy'가'false'이기 때문에 일해야합니다. – ThomasReggi