错误:连接ECONNREFUSED

时间:2016-06-21 12:22:06

标签: javascript node.js server

这是我的节点服务器:

var https = require('https'),
    http = require('http'),
    qs = require('querystring'),
    request = require('request'),
    username = 'user',
    password = 'pass',

colors = require('colors'),

port = 6969;

function onRequest(client_req, client_res) {
    var query = client_req.url.substring(1);

    console.log("proxying " + client_req.url);

    var options = {
        host: 'http://'+username + ':' + password + '@site.subs.com',
        port: 443,
        path: '/api/v1/subs/?lang=it&format=html' + query,
        method: 'GET',
        gzip:true,
        headers: {
            accept: '*/*'
        }
    };

    var connector = https.request(options, function (res) {
        res.pipe(client_res, {end: true});//tell 'response' end=true
        console.log(res);
    });

    // Website you wish to allow to connect
    client_res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000');

    // Request methods you wish to allow
    client_res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');

    // Request headers you wish to allow
    client_res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');

    // Set to true if you need the website to include cookies in the requests sent
    // to the API (e.g. in case you use sessions)
    client_res.setHeader('Access-Control-Allow-Credentials', true);

    client_req.pipe(connector, {end: true});

    console.log(connector);

}

http.createServer(onRequest).listen(port);

process.on('uncaughtException', function (err) {
    console.log(err);
});

我试图通过使用基本的sintax“主机:'http://'+用户名+':'+密码+'@ site.subs.com'在基本身份验证中进行身份验证但我收到此错误:错误:连接ECONNREFUSED ,然后是ip和port。

我做错了什么?

0 个答案:

没有答案