[英]Node.js http requests and cookies with http module
How do I use http module to make GET requests with a query string and cookies? 如何使用http模块通过查询字符串和cookie发出GET请求?
GET someurl?test=one
Cookies: name=john; Cookies:name = john; name1=mary;
name1 =玛丽;
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.