[英]Socket Hangup Error in Node.js on using https
我正在嘗試通過使用安全連接https的Nodejs使用HTTP GET方法。 這是我的代碼:
var https = require('https');
https.globalAgent.options.secureProtocol = 'SSLv3_method';
var options = {
host: 'my_proxy_address',
port: 3128,
path: 'https://birra-io2014.appspot.com/_ah/api/birra/v1/beer',
method: 'GET',
headers: {
accept: '*/*'
}
};
var req = https.request(options, function(res) {
console.log(res.statusCode);
res.on('data', function(d) {
process.stdout.write(d);
});
});
req.end();
req.on('error', function(e) {
console.error(e);
});
當我運行它時,我得到一個錯誤:
{ [Error: socket hang up] code: 'ECONNRESET', sslError: undefined }
我無法使用HTTP,因為appspot需要https。 請幫忙! 提前致謝。
請嘗試以下代碼。 (對我有用)
var https = require('https');
var options = {
port: 443,
host: 'birra-io2014.appspot.com',
path: '/_ah/api/birra/v1/beer',
method: 'GET',
headers: {
accept: '*/*'
}
};
var req = https.request(options, function(res) {
console.log("statusCode: ", res.statusCode);
console.log("headers: ", res.headers);
res.on('data', function(d) {
process.stdout.write(d);
});
});
req.end();
req.on('error', function(e) {
console.error('ERROR object ==>' + e);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.