2012-05-27 4 views
6

나는 the sample from the documentation을 시도했으며 훌륭하게 작동합니다.Node.js Https 요청 오류

그러나 URL을 https://api.mercadolibre.com/sites/으로 변경하면 요청이 중단됩니다. 내가 얻을 수있는 유일한 방법은 다음과 같습니다

var https = require('https'); 

this.dispatch = function(req, res) { 
    var renderHtml = function(content) { 
    res.writeHead(200, {'Content-Type': 'text/html'}); 
    res.end(content, 'utf-8'); 
    } 

    var parts = req.url.split('/'); 

    var options = { 
    host: 'api.mercadolibre.com', 
    port: 443, 
    path: '/sites/', 
    method: 'GET' 
    }; 

    var request = https.request(options, function(res) { 
    console.log("statusCode: ", res.statusCode); 
    console.log("headers: ", res.headers); 

    res.on('data', function(d) { 
     process.stdout.write(d); 
    }); 
    }); 

    request.on('error', function(e) { 
    console.error('error'); 
    console.error(e); 
    }); 

    request.end(); 
    return 'item id:' + parts[2]; 
}; 

나는 컬, soapui로하고 브라우저로 시도했다 :

{ [Error: socket hang up] code: 'ECONNRESET' } 

여기 내 코드입니다. 모든 경우에 훌륭하게 작동하지만 node.js에서는 작동하지 않습니다.

어떻게 진행되고 있는지에 대해 더 많은 데이터를 얻을 수 있습니까?

내가 할 컬

추가 : --sslv3 https://api.mercadolibre.com/sites/ 작품 말림. 나는 centos 6에서 똑같은 것을 테스트했고 너무 효과적이었다. 이번에는 소스에서 동일한 문제가 발생하여 노드를 다시 설치했습니다. 내 OS는 우분투 12.04입니다. 감사합니다. .

+0

다음과 같이 표시해야합니다. 우리가 문제를 진단 할 수 있도록 사용하고 있습니다. – Ashe

답변

2

request과 같은 라이브러리를 사용하여 세부 정보를 처리하지 않는 이유는 무엇입니까?

var request = require('request'); 

request('https://api.mercadolibre.com/sites/', {}, function(err, res, body) { 
    console.log("Got body: ", body); 
}); 

이 수익률 :

Got body: [{"id":"MLA","name":"Argentina"},{"id":"MLB","name":"Brasil"},{"id":"MCO","name":"Colombia"},{"id":"MCR","name":"Costa Rica"},{"id":"MEC","name":"Ecuador"},{"id":"MLC","name":"Chile"},{"id":"MLM","name":"Mexico"},{"id":"MLU","name":"Uruguay"},{"id":"MLV","name":"Venezuela"},{"id":"MPA","name":"Panamá"},{"id":"MPE","name":"Perú"},{"id":"MPT","name":"Portugal"},{"id":"MRD","name":"Dominicana"}] 
+0

똑같은 것. 어떻게하면 더 많은 데이터를 얻을 수 있습니까? –

+0

"똑같은 것"이라고 말하면'{[오류 : 소켓 끊기] 코드 : 'ECONNRESET'}'가 다시 나타납니다. 사용자의 IP 또는 기타 액세스를 차단하고있는 것 같습니다. – Ashe

+0

예 정확히 동일합니다. 내 IP를 차단하는 무언가, 아마도 node.js 요청을 차단하는 뭔가가 있다고 생각하지 않습니다. 지금은 노드 스크립트 (그리고 작동) 내부에서 exec curl을 사용하고 있습니다. 내 요청을 차단하는 것에 대한 자세한 정보를 얻을 수있는 방법이 있습니까? –

0

난 당신이 요청 지정해야 프록시 뒤에 생각합니다. 프록시 설정은 node-curl이 사용하는 libcurl에 의해 자동으로 감지됩니다. 따라서 요청은 노드 컬 (node-curl)로 전달됩니다.

따라서, 조직에서 사용하는 프록시 IP와 포트를 찾아,이 시도 : 그것은 컬 작업 때문에

var request = require('request'); 
request({ 
    uri : 'https://mail.google.com/mail', 
    proxy : 'http://<proxy ip>:<proxy port>' 
}, function (error, response, body) { 
    if (!error && response.statusCode == 200) { 
     console.log(body) // Print the google web page. 
    }else{ 
     console.log(error); 
     console.log(response.statusCode); 
    } 
}) 
3

, 노드 컬 모듈을 사용해보십시오. 나는 하루 종일 node-curl로 전환 할 때까지 http 및/또는 https 모듈로 node.js에서 작동하도록 만들었습니다.

var curl = require('node-curl'); 
curl('https://api.mercadolibre.com/sites/', {SSLVERSION: 3}, function(err, res) { 
    var body = res.body; 
    res.close(); 
    console.log(body); 
}); 
7

내가 api.mercadolibre.com 사이트에 대한 모르겠지만, 내가 다음 코드처럼 port PARAM을 제거하면 나는 API 호출 할 수 있습니다 :

이 시도

var options = { 
    host: 'api.mercadolibre.com', 
    path: '/sites/', 
    method: 'GET' 
}; 

그리고 우리는 또한 추가 필요 SSL 버전 3을 지원하는 param :

https.globalAgent.options.secureProtocol = 'SSLv3_method'; 
+2

'SSLv3_method'는 2 년 된 문제를 해결하는 데 도움이되었습니다! 고마워요! –

1

여기와 마찬가지로 컬링으로 작동하지만 node.js.

문제점 : 여기 CentOS-5 curl usesthe는 openssl 라이브러리를 제공하므로 CA 검사를 위해 centos 표준 /etc/pki/tls/certs/ca-bundle.crt를 사용합니다.

node.js는 어디에서 찾을 수 있습니까? strace를 통해 확인을 위해 CA 파일에 대한 참조를 볼 수 없습니다. 잘 알려진 구형 발급자의 유효한 SSL 인증서를 사용하는 서버에 대한 Node.js 요청이 수락되지만 자체 CA가있는 내 웹 서버에는 적용되지 않습니다. ca-bundle.crt 파일에 내 CA.crt를 넣었으므로 이제는 curl이 accept하지만 node.js는 허용하지 않습니다.당신은이다

post_options.path = 'history'; 
... 
var req = http.request(post_options, function(res) { 
... 

:이 작업을 수행 할 경우

var client = require('https'); 
    var download_options = url.parse(sourceUrl); 
    download_options.method = "GET"; 
    download_options.agent = false; 
    download_options.rejectUnauthorized = false;/HERE to accept all SSL-certificates */ 

    var download_request = client.request(download_options); 
0

당신은 ECONNRESET 오류가 발생합니다 :

는 지금

유일한 해결책은 내 dev에 박스에 대한 확인 검사를 비활성화하는 것입니다 경로에 /이 있는지 확인해야합니다.

post_options.path = '/history'; 
...