Node.js http请求和带有http模块的cookie

时间:2014-04-02 16:43:44

标签: node.js http

如何使用http模块通过查询字符串和Cookie发出GET请求?

GET someurl?test=one

Cookies:name = john; NAME1 =玛丽;

1 个答案:

答案 0 :(得分:0)

var http = require('http');
var url_parser = require("url");

var url = "someurl?test=one";
var url_parts = url_parser.parse(url);

var options = {host: url_parts.hostname, port: url_parts.port|80, path: url_parts.path};

var request = http.request(options, function(response) {

    //do something with the response

}).on('error',function(e){
    //error happened
});

request.setHeader( 'cookie', YOUR_COOKIE );

request.end();