function getCookies(){
request('http://google.com', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(response.headers);
}
})
}
结果
{ date: 'Fri, 11 Dec 2015 07:15:50 GMT',
expires: '-1',
'cache-control': 'private, max-age=0',
'content-type': 'text/html; charset=EUC-KR',
p3p: 'CP="This is not a P3P policy! See https://www.google.com/support/accounts/answer/151657?hl=en for more info."',
server: 'gws',
'x-xss-protection': '1; mode=block',
'x-frame-options': 'SAMEORIGIN',
'set-cookie':
[ 'PREF=ID=1111111111111111:FF=0:TM=1449818150:LM=1449818150:V=1:S=Q3BB20FA6TkaZymd; expires=Thu, 31-Dec-2015 16:02:17 GMT; path=/; domain=.google.co.kr',
'NID=74=hnriWxk7N9jHtP5W0qgaxrwD1YuNKOmJg748ucxWilu9jaqHJVovfkYdvMr0tlp-VToID5cdTNDSXNXqr4M8umJ9traab67x2xZKfu3hJbsBRXeVvyiCOcwZ8bkXNcU4; expires=Sat, 11-Jun-2016 07:15:50 GMT; path=/; domain=.google.co.kr; HttpOnly' ],
'accept-ranges': 'none',
vary: 'Accept-Encoding',
connection: 'close' }
我想从响应头中获取' set-cookie '的值。如何捡起来?有什么酷而简单的方法吗?我应该使用filedkey的for语句,还是。我该怎么办?我不知道我是Java的新手。谢谢...
function getCookies(callback){
request('http://google.com', function (error, response, body) {
if (!error && response.statusCode == 200) {
return callback(null, response.headers['set-cookie']);
} else {
return callback(error);
}
})
}
那么您可以致电:
getCookies(function(err, res){
if(!err)
console.log(res)
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句