http request from nodejs to django

We have a django app and I need to add some functionality with NodeJS. I've been following this example: http://www.maxburstein.com/blog/realtime-django-using-nodejs-and-socketio/ using socket.io and it works perfect on localhost. Now, the problem comes when moving the application to apache server. I need to send a POST request to django and all I get is a timeout response.

Our django app over apache is listening on port 80 and node is listening on port 4000. The config for the http request is as follows:

var options = {
        hostname: 'hostaddress',
        port: '80',
        path: '/dashboards/datosinforme/',
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Content-Length': values.length
        }
    };
    var req = http.request(options, function(res){
        res.setEncoding('utf8');
        var data_obj = "";
        res.on('data',function(data){
            data_obj+=data;
        });
        res.on('end', function(){
            ...some functionality...
        });
    });
    req.write(values);
    req.end();

I've tried both local and public IPs. I get no response from django using the public IP and Bad Request using the local IP.

I'd be eternally grateful if anyone could help. Thanks in advance.

Edit: Ok, I now tried with 127.0.0.1 as hostname (because both node and django are on the same machine) and I get a Bad Request response, but I don't really see anything wrong in it:

POST /dashboards/datosinforme HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 174
Host: 127.0.0.1:80
Connection: keep-alive

id=5&tipo_de_fecha=d&time_zone=Europe%2FBerlin

Ok, I got it. I just had to include 127.0.0.1 in the ALLOWED_HOSTS parametter in settings.py and no more bad requests from django.

链接地址: http://www.djcxy.com/p/89110.html

上一篇: 查尔斯调试代理不连接到本地主机

下一篇: 从nodejs到Django的http请求