[英]Use node.js to cache cookies?
大家好,我只是从node.js开始,然后尝试使一个机器人在某个站点上为我发送东西,该站点使用cookie保存登录数据,成功后,我将HTTP HTTP发布到相同的站点,但目录不同并且我已注销,所以我想知道是否有任何缓存方法?
There is a whole article about it. 有整篇文章 。
And here is a module for that . 这是该模块 。
It is not that simple, you have to use external module for that (link above): 并不是那么简单,您必须为此使用外部模块(上面的链接):
var http = require( "http" )
var Cookies = require( "cookies" )
server = http.createServer( function( req, res ) {
var cookies = new Cookies( req, res, keys )
, unsigned, signed, tampered
if ( req.url == "/set" ) {
cookies
// set a regular cookie
.set( "unsigned", "foo", { httpOnly: false } )
// set a signed cookie
.set( "signed", "bar", { signed: true } )
// mimic a signed cookie, but with a bogus signature
.set( "tampered", "baz" )
.set( "tampered.sig", "bogus" )
res.writeHead( 302, { "Location": "/" } )
return res.end( "Now let's check." )
}
unsigned = cookies.get( "unsigned" )
signed = cookies.get( "signed", { signed: true } )
tampered = cookies.get( "tampered", { signed: true } )
assert.equal( unsigned, "foo" )
assert.equal( signed, "bar" )
assert.notEqual( tampered, "baz" )
assert.equal( tampered, undefined )
res.writeHead( 200, { "Content-Type": "text/plain" } )
res.end(
"unsigned expected: foo\n\n" +
"unsigned actual: " + unsigned + "\n\n" +
"signed expected: bar\n\n" +
"signed actual: " + signed + "\n\n" +
"tampered expected: undefined\n\n"+
"tampered: " + tampered + "\n\n"
)
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.