NodeJS对Intersango.com的HTTPS请求

时间:2013-02-07 21:00:12

标签: javascript api node.js https bitcoin

我正在制作的请求有问题,我无法理解。根据{{​​3}},似乎一切都井然有序。

以下是代码:

var request = require('https').request;

var opts = {
  host: 'intersango.com',
  method: 'GET',
  path: '/api/ticker.php',
  port: 443,
  accept: '*/*',
  headers: { 'User-Agent': 'Mozilla/5.0 (X11; Linux i686; rv:10.0) Gecko/20100101 Firefox/10.0' } };

var req = request(opts, function (result) {
        result.setEncoding('utf8');
        var buffer = '';
        result.on('data', function(data) {
            buffer += data;
        });
        result.on('end', function() {
            console.log('<- Received ' + buffer.length + ' bytes');
            var data = JSON.parse(buffer);
            console.log(data);
        });
    });

req.on('error', function(e) {
        console.log('warning: problem with request: ' + e.message);
    });

console.log('-> ' + opts['method'] + ' ' + opts['host'] + ':' + opts['port'] + opts['path']);

req.end();

这是输出:

$> node test.intersango.js
-> GET intersango.com:443/api/ticker.php
warning: problem with request: socket hang up

有趣的是,如果您在浏览器中转到API spec则可以,,但如果您只是转到https://intersango.com/api/ticker.php 则不行。我尝试了一些intersango.com:443/api/ticker.php,但它只是提供了warning: problem with request: connect ECONNREFUSED

注意:尝试POST无法帮助

1 个答案:

答案 0 :(得分:0)

要确认,降级Node确实解决了这个问题。