Node.js对ASP脚本的服务器端HTTP请求

时间:2022-03-09 16:56:47

Currently building an application in node.js. I am trying to make a server-side HTTP request to an ASP script and return the results.

目前正在node.js中构建一个应用程序。我试图向ASP脚本发出服务器端HTTP请求并返回结果。

If I navigate to the url in my browser, everything is fine. Data is returned. However, when I do this in node.js using restler, or any other module for that matter. I get nothing back......UNTIL I add the ASP.NET_SessionId cookie to the header of the request. I copied this cookie from the successul GET from my browser.

如果我在浏览器中导航到网址,一切都很好。返回数据。但是,当我在node.js中使用restler或任何其他模块执行此操作时。我得不到任何回报......直到我将ASP.NET_SessionId cookie添加到请求的标头中。我从浏览器中复制了来自成功GET的cookie。

How do I get/set this session cookie server-side in node.js?

如何在node.js中获取/设置此会话cookie服务器端?

Using express framework. Code below.

使用快速框架。代码如下。

app.js

/**
 * Module dependencies.
 */

var express = require('express')
  , routes = require('./routes')
  , user = require('./routes/user')
  , http = require('http')
  , path = require('path');

var app = express();

app.configure(function(){
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(express.cookieParser('cat'));
  app.use(express.session());
  app.use(app.router);
  app.use(express.static(path.join(__dirname, 'public')));
});

app.configure('development', function(){
  app.use(express.errorHandler());
});

app.get('/', routes.index);
app.get('/users', user.list);

http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});

route index.js

/*
 * GET home page.
 */

exports.index = function(req, res){

    var http = require("http"),
    sys = require('util'),
    rest = require('restler');

    rest.get('http://192.168.154.134/dca/stream/StreamDown.asp?' +
        'Action=GetRepositoryConnections' , {headers:{
        'Cookie':'ASP.NET_SessionId=jj1jx255wlkwib45gq0d3555;' +
        ' ASPSESSIONIDASDDSBQR=ACABCJNDIIONGGMPGAOMMJJD;' +
        ' ASPSESSIONIDCQQRQDQR=BAIBCEODMMKAPJAOLLMMDNEJ;' +
        ' ASPSESSIONIDAQSTRAQR=KMLDIOODECFNBKPGINLLNBKC;' +
        ' ASPSESSIONIDASQQQDQR=OKGBKCPDHDIKAJNOGFKACCCG'}

    }).on('complete', function(result) {

        if (result instanceof Error) {
            sys.puts('Error: ' + result.message);
            this.retry(5000); // try again after 5 sec
        } else {
            sys.puts(result);
        }
    });

    res.render('index', { title: 'Express' });

};

1 个解决方案

#1


0  

Try request. It has a "cookie jar" so it will remember cookies for you.

试试请求。它有一个“饼干罐”,所以它会记住你的饼干。

#1


0  

Try request. It has a "cookie jar" so it will remember cookies for you.

试试请求。它有一个“饼干罐”,所以它会记住你的饼干。