2017-12-01 13 views
0

나는 프록시를 사용하고 있습니다. 노드 스크립트로 storage.googleapis.com에서 zip 파일을 다운로드하려고합니다.https 모듈로 프록시 요청을 할 수 없습니다.

나는 제대로 환경 나는에서 오전 프로세스에 대한 변수와 명령으로 curl 작품과 파일 다운로드 등의 HTTPS_PROXYHTTP_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) 
}) 
+0

'407'은'프록시 인증 Required'이지만, I는'username'를 통과 할 때'난'로컬 발행자를 얻을 수없는 얻을 프록시 전역에 password' 'secureProxy'가'false'이기 때문에 일해야합니다. – ThomasReggi

답변

0

추가 result.rejectUnauthorized = false 수정 및

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); 
    } 
    result.rejectUnauthorized = false 
    return result; 
} 
+0

이것은 더 이상 작동하지 않습니다. – ThomasReggi