应用判断是否一个用户是否登录主要是通过cookie,而浏览器最终发给服务器的是一个标准的http头,比如下面的:
GET /pc/myInfo HTTP/1.1
Accept: */*
Accept-Language: zh-cn
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB6; .NET CLR 2.0.50727; CIBA; InfoPath.2)
Host: wenda.sogou.com
Connection: Keep-Alive
Cookie: SUID=aifGPyes
而wget支持 –head 的方式将这个请求拼出来,所以我们就可以构造一个下面的http请求:
wget --head "Accept: */*" --head "Accept-Language: zh-cn" --head "Accept-Encoding: gzip, deflate" --head "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB6; .NET CLR 2.0.50727; CIBA; InfoPath.2)" --head "Host: wenda.sogou.com "-head "Connection: Keep-Alive" --head "Cache-Control: no-cache" --head "Cookie: SUID=aifGPyes" http://wenda.sogou.com/pc/myInfo
这样就可以获取需要登陆的内容了。