五、附录
附录一 163 登录时请求和发送数据包
(1) GET
http://adgeo.163.com/ad_cookies
请求头部
GET /ad_cookies HTTP/1.1
Accept: */*
Referer: http://mail.163.com/
Accept-Language: zh-cn,en-US;q=0.5
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; MyIE2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; CIBA)
Host: adgeo.163.com
Connection: Keep-Alive
应答头部
HTTP/1.1 200 OK
Server: nginx/ 0.7.24
Date: Tue, 02 Dec 2008 06:40:45 GMT
Content-Type: text/plain
Content-Length: 0
Connection: close
Cache-Control: no-cache
P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"
Set-Cookie: Province=025; Expires=Tue, 16 Dec 2008 06:40:45 GMT; Path=/; Domain=.163.com
(2) POST
https://reg.163.com/logins.jsp?type=1&url=http://fm163.163.com/coremail/fcg/ntesdoor2?lightweight%3D1%26verifycookie%3D1%26language%3D-1%26style%3D-1
请求头部
POST /logins.jsp?type=1&url=http://fm163.163.com/coremail/fcg/ntesdoor2?lightweight%3D1%26verifycookie%3D1%26language%3D-1%26style%3D-1 HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/x-shockwave-flash, */*
Referer: http://mail.163.com/
Accept-Language: zh-cn,en-US;q=0.5
Content-Type: application/x-www-form-urlencoded
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; MyIE2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; CIBA)
Host: reg.163.com
Content-Length: 131
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: Province=025; ntes_mail_firstpage=normal
请求体
verifycookie=1&style=-1&product=mail163&username=xjtujay&password=jinjian&selType=-1&remUser=on&secure=on&%B5%C7%C2%BC%D3%CA%CF%E4=
应答头部
HTTP/1.1 200 OK
Date: Tue, 02 Dec 2008 06:40:56 GMT
Server: Apache
Cache-Control: max-age=0
Expires: Tue, 02 Dec 2008 06:40:56 GMT
Pragma: No-cache
Cache-Control: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Length: 2575
Set-Cookie: NTES_SESS=NYQeUfIIQZhT16_9RKAAz36JIgKh2aGz7IeDK8H.pFklFNEUgF1EKWkKAgAhPL.F30AmD5YMQLzsQ1CjkLkdLSsVF; domain=.163.com; path=/
Set-Cookie: NETEASE_SSN=xjtujay; domain=.163.com; path=/; expires=Wed, 02-Dec-2009 06:40:54 GMT
Set-Cookie: NETEASE_ADV=11&23&1228200054655; domain=.163.com; path=/; expires=Wed, 02-Dec-2009 06:40:54 GMT
Set-Cookie: URSJESSIONID=aGHZvw0enBrb; path=/
Connection: close
Content-Type: text/html; charset=UTF-8
应答内容
window.location.replace("http://reg.163.com/crossdomain.jsp?username=xjtujay&loginCookie=NYQeUfIIQZhT16_9RKAAz36JIgKh2aGz7IeDK8H.pFklFNEUgF1EKWkKAgAhPL.F30AmD5YMQLzsQ1CjkLkdLSsVF&url=http% 3A % 2F %2Ffm163.163.com%2Fcoremail%2Ffcg%2Fntesdoor2%3Flightweight%3D1%26verifycookie%3D1%26language%3D-1%26style%3D-1%26username%3Dxjtujay");//remain for popo ,don't del
正在登录...请稍等
(3) GET
http://reg.163.com/crossdomain.jsp?username=xjtujay&loginCookie=NYQeUfIIQZhT16_9RKAAz36JIgKh2aGz7IeDK8H.pFklFNEUgF1EKWkKAgAhPL.F30AmD5YMQLzsQ1CjkLkdLSsVF&url=http%3A%2F%2Ffm163.163.com%2Fcoremail%2Ffcg%2Fntesdoor2%3Flightweight%3D1%26verifycookie%3D1%26language%3D-1%26style%3D-1%26username%3Dxjtujay
请求头部
GET /crossdomain.jsp?username=xjtujay&loginCookie=NYQeUfIIQZhT16_9RKAAz36JIgKh2aGz7IeDK8H.pFklFNEUgF1EKWkKAgAhPL.F30AmD5YMQLzsQ1CjkLkdLSsVF&url=http% 3A % 2F %2Ffm163.163.com%2Fcoremail%2Ffcg%2Fntesdoor2%3Flightweight%3D1%26verifycookie%3D1%26language%3D-1%26style%3D-1%26username%3Dxjtujay HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/x-shockwave-flash, */*
Accept-Language: zh-cn,en-US;q=0.5
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; MyIE2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; CIBA)
Host: reg.163.com
Connection: Keep-Alive
Cookie: Province=025; ntes_mail_firstpage=normal; NTES_SESS=NYQeUfIIQZhT16_9RKAAz36JIgKh2aGz7IeDK8H.pFklFNEUgF1EKWkKAgAhPL.F30AmD5YMQLzsQ1CjkLkdLSsVF; NETEASE_SSN=xjtujay; NETEASE_ADV=11&23&1228200054655; URSJESSIONID=aGHZvw0enBrb
应答头部
HTTP/1.1 200 OK
Date: Tue, 02 Dec 2008 06:40:52 GMT
Server: Apache
Cache-Control: max-age=0
Expires: Tue, 02 Dec 2008 06:40:52 GMT
Pragma: No-cache
Cache-Control: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Length: 2145
Connection: close
Content-Type: text/html; charset=UTF-8
应答内容
window.location.replace("http://fm163.163.com/coremail/fcg/ntesdoor2?lightweight=1&verifycookie=1&language=-1&style=-1&username=xjtujay");//remain for popo ,don't del
< META HTTP-EQUIV=REFRESH CONTENT="0;URL=http://fm163.163.com/coremail/fcg/ntesdoor2?lightweight=1&verifycookie=1&language=-1&style=-1&username=xjtujay">
正在登录...请稍等
(4) GET
http://fm163.163.com/coremail/fcg/ntesdoor2?lightweight=1&verifycookie=1&language=-1&style=-1&username=xjtujay
请求头部
GET /coremail/fcg/ntesdoor2?lightweight=1&verifycookie=1&language=-1&style=-1&username=xjtujay HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/x-shockwave-flash, */*
Accept-Language: zh-cn,en-US;q=0.5
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; MyIE2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; CIBA)
Host: fm163.163.com
Connection: Keep-Alive
Cookie: Province=025; ntes_mail_firstpage=normal; NTES_SESS=NYQeUfIIQZhT16_9RKAAz36JIgKh2aGz7IeDK8H.pFklFNEUgF1EKWkKAgAhPL.F30AmD5YMQLzsQ1CjkLkdLSsVF; NETEASE_SSN=xjtujay; NETEASE_ADV=11&23&1228200054655
应答头部
HTTP/1.1 302 Found
Date: Tue, 02 Dec 2008 06:40:56 GMT
Server: Apache
Set-Cookie: Coremail=TYlruaxjaLMaE%TBrNkFKKhBjsxfeRvrKKnDlwogztEEjg; path=/; domain=163.com
Location: http://tg 1a 89.mail.163.com/a/j/js3/main.jsp?sid=TBrNkFKKhBjsxfeRvrKKnDlwogztEEjg
Content-Length: 264
Connection: close
Content-Type: text/html; charset=iso-8859-1
应答内容
Found
The document has moved here.
附录二 通讯录示例HTML
不分页
>每页10项
>每页20项
>每页50项
>每页100项
全部分组
朋友 亲人 同事 网友 常用联系人
朋友 亲人 同事 网友 常用联系人
xmp = document.getElementById("t 1");
xmp = xmp.innerHTML.split("
i = 1 - 1;
obj.row[i] = new Object();
obj.row[i].chkname = "chk-_0_7_";
obj.row[i].chkvalue = "0064235%40sina.com";
obj.row[i].iname = xmp[0];
obj.row[i].iemail = xmp[1];
obj.row[i].asend = "/coremail/fcg/ldmmapp?sid=XApcTnKKGzpsqgDHliKKgiYNjfXyQlnK&funcid=compose&to=%22%D5%C5%D0%F1%22%20% 3C 0064235%40sina.com%3E";
obj.row[i].afind = "/coremail/fcg/ldsrchapp?funcid=srchhand&sid=XApcTnKKGzpsqgDHliKKgiYNjfXyQlnK&word=0064235%40sina.com&fromonly=yes&fid=0&subfolder=yes&perfectmatch=1&rtnurl=%2Fcoremail%2Ffcg%2Fldvcapp%3Ffuncid%3Daddress%26sid%3DXApcTnKKGzpsqgDHliKKgiYNjfXyQlnK%26tempname%3Daddress%252Faddress.htm%26ifirstv%3D%26listnum%3D0%26showlist%3Dall%26total%3D26";
obj.row[i].ainfo = "/coremail/fcg/ldvcapp?funcid=prtsearchres&sid=XApcTnKKGzpsqgDHliKKgiYNjfXyQlnK&iid=7&mode=1&emptymode=1&print.x=1&tempname=address/add.htm";
obj.row[i].aedit = "/coremail/fcg/ldvcapp?funcid=loadiadd&iid=7&sid=XApcTnKKGzpsqgDHliKKgiYNjfXyQlnK&ifirstv=&lid=&modify.x=1";
xmp = document.getElementById("t 2");
xmp = xmp.innerHTML.split("
i = 2 - 1;
obj.row[i] = new Object();
obj.row[i].chkname = "chk-_0_11_";
obj.row[i].chkvalue = "yankebin%40163.com";
obj.row[i].iname = xmp[0];
obj.row[i].iemail = xmp[1];
obj.row[i].asend = "/coremail/fcg/ldmmapp?sid=XApcTnKKGzpsqgDHliKKgiYNjfXyQlnK&funcid=compose&to=%22%D1%D5%BF%CB%B1%F3%22%20%3Cyankebin%40163.com%3E";
obj.row[i].afind = "/coremail/fcg/ldsrchapp?funcid=srchhand&sid=XApcTnKKGzpsqgDHliKKgiYNjfXyQlnK&word=yankebin%40163.com&fromonly=yes&fid=0&subfolder=yes&perfectmatch=1&rtnurl=%2Fcoremail%2Ffcg%2Fldvcapp%3Ffuncid%3Daddress%26sid%3DXApcTnKKGzpsqgDHliKKgiYNjfXyQlnK%26tempname%3Daddress%252Faddress.htm%26ifirstv%3D%26listnum%3D0%26showlist%3Dall%26total%3D26";
obj.row[i].ainfo = "/coremail/fcg/ldvcapp?funcid=prtsearchres&sid=XApcTnKKGzpsqgDHliKKgiYNjfXyQlnK&iid=11&mode=1&emptymode=1&print.x=1&tempname=address/add.htm";
obj.row[i].aedit = "/coremail/fcg/ldvcapp?funcid=loadiadd&iid=11&sid=XApcTnKKGzpsqgDHliKKgiYNjfXyQlnK&ifirstv=&lid=&modify.x=1";
xmp = document.getElementById("t 3");
xmp = xmp.innerHTML.split("
i = 3- 1;
obj.row[i] = new Object();
obj.row[i].chkname = "chk-_0_17_";
obj.row[i].chkvalue = "abuse%40service.netease.com";
obj.row[i].iname = xmp[0];
obj.row[i].iemail = xmp[1];
obj.row[i].asend = "/coremail/fcg/ldmmapp?sid=XApcTnKKGzpsqgDHliKKgiYNjfXyQlnK&funcid=compose&to=%22abuse%22%20%3Cabuse%40service.netease.com%3E";
obj.row[i].afind = "/coremail/fcg/ldsrchapp?funcid=srchhand&sid=XApcTnKKGzpsqgDHliKKgiYNjfXyQlnK&word=abuse%40service.netease.com&fromonly=yes&fid=0&subfolder=yes&perfectmatch=1&rtnurl=%2Fcoremail%2Ffcg%2Fldvcapp%3Ffuncid%3Daddress%26sid%3DXApcTnKKGzpsqgDHliKKgiYNjfXyQlnK%26tempname%3Daddress%252Faddress.htm%26ifirstv%3D%26listnum%3D0%26showlist%3Dall%26total%3D26";
obj.row[i].ainfo = "/coremail/fcg/ldvcapp?funcid=prtsearchres&sid=XApcTnKKGzpsqgDHliKKgiYNjfXyQlnK&iid=17&mode=1&emptymode=1&print.x=1&tempname=address/add.htm";
obj.row[i].aedit = "/coremail/fcg/ldvcapp?funcid=loadiadd&iid=17&sid=XApcTnKKGzpsqgDHliKKgiYNjfXyQlnK&ifirstv=&lid=&modify.x=1";
xmp = document.getElementById("t 19");
xmp = xmp.innerHTML.split("
i = 19 - 1;
obj.row[i] = new Object();
obj.row[i].chkname = "chk-_0_18_";
obj.row[i].chkvalue = "peter%40mail.xjtu.edu.cn";
obj.row[i].iname = xmp[0];
obj.row[i].iemail = xmp[1];
obj.row[i].asend = "/coremail/fcg/ldmmapp?sid=XApcTnKKGzpsqgDHliKKgiYNjfXyQlnK&funcid=compose&to=%22peter%22%20%3Cpeter%40mail.xjtu.edu.cn%3E";
obj.row[i].afind = "/coremail/fcg/ldsrchapp?funcid=srchhand&sid=XApcTnKKGzpsqgDHliKKgiYNjfXyQlnK&word=peter%40mail.xjtu.edu.cn&fromonly=yes&fid=0&subfolder=yes&perfectmatch=1&rtnurl=%2Fcoremail%2Ffcg%2Fldvcapp%3Ffuncid%3Daddress%26sid%3DXApcTnKKGzpsqgDHliKKgiYNjfXyQlnK%26tempname%3Daddress%252Faddress.htm%26ifirstv%3D%26listnum%3D0%26showlist%3Dall%26total%3D26";
obj.row[i].ainfo = "/coremail/fcg/ldvcapp?funcid=prtsearchres&sid=XApcTnKKGzpsqgDHliKKgiYNjfXyQlnK&iid=18&mode=1&emptymode=1&print.x=1&tempname=address/add.htm";
obj.row[i].aedit = "/coremail/fcg/ldvcapp?funcid=loadiadd&iid=18&sid=XApcTnKKGzpsqgDHliKKgiYNjfXyQlnK&ifirstv=&lid=&modify.x=1";
附录三 Cookie以及CookieHandler的实现
Cookie的实现
import java.net.*;
import java.text.*;
import java.util.*;
public class Cookie {
String name;
String value;
URI uri;
String domain;
Date expires;
String path;
private static DateFormat expiresFormat1
= new SimpleDateFormat("E, dd MMM yyyy k:m:s 'GMT'", Locale.US);
private static DateFormat expiresFormat2
= new SimpleDateFormat("E, dd-MMM-yyyy k:m:s 'GMT'", Locale.US);
/**
* Construct a cookie from the URI and header fields
*
* @param uri URI for cookie
* @param header Set of attributes in header
*/
public Cookie(URI uri, String header) {
String attributes[] = header.split(";");
String nameValue = attributes[0].trim();
this.uri = uri;
this.name =
nameValue.substring(0, nameValue.indexOf('='));
this.value =
nameValue.substring(nameValue.indexOf('=')+1);
this.path = "/";
this.domain = uri.getHost();
for (int i=1; i < attributes.length; i++) {
nameValue = attributes[i].trim();
int equals = nameValue.indexOf('=');
if (equals == -1) {
continue;
}
String name = nameValue.substring(0, equals);
String value = nameValue.substring(equals+1);
if (name.equalsIgnoreCase("domain")) {
String uriDomain = uri.getHost();
if (uriDomain.equals(value)) {
this.domain = value;
} else {
if (!value.startsWith(".")) {
value = "." + value;
}
uriDomain = uriDomain.substring(
uriDomain.indexOf('.'));
if (!uriDomain.equals(value)) {
throw new IllegalArgumentException(
"Trying to set foreign cookie");
}
this.domain = value;
}
} else if (name.equalsIgnoreCase("path")) {
this.path = value;
} else if (name.equalsIgnoreCase("expires")) {
try {
this.expires = expiresFormat1.parse(value);
} catch (ParseException e) {
try {
this.expires = expiresFormat2.parse(value);
} catch (ParseException e2) {
throw new IllegalArgumentException(
"Bad date format in header: " + value);
}
}
}
}
}
public boolean hasExpired() {
if (expires == null) {
return false;
}
Date now = new Date();
return now.after(expires);
}
public String getName() {
return name;
}
public URI getURI() {
return uri;
}
/**
* Check if cookie isn't expired and if URI matches,
* should cookie be included in response.
*
* @param uri URI to check against
* @return true if match, false otherwise
*/
public boolean matches(URI uri) {
if (hasExpired()) {
return false;
}
String path = uri.getPath();
if (path == null) {
path = "/";
}
return path.startsWith(this.path);
}
public String toString() {
StringBuilder result = new StringBuilder(name);
result.append("=");
result.append(value);
return result.toString();
}
}
CookieHandler的实现
import java.io.*;
import java.net.*;
import java.util.*;
public class ListCookieHandler extends CookieHandler {
// "Long" term storage for cookies, not serialized so only
// for current JVM instance
private List
/**
* Saves all applicable cookies present in the response headers into cache.
*
* @param uri
* URI source of cookies
* @param responseHeaders
* Immutable map from field names to lists of field values
* representing the response header fields returned
*/
public void put(URI uri, Map
throws IOException {
System.out.println("Cache: " + cache);
List
if (setCookieList != null) {
for (String item : setCookieList) {
Cookie cookie = new Cookie(uri, item);
// Remove cookie if it already exists
// New one will replace
for (Cookie existingCookie : cache) {
if ((cookie.getURI().equals(existingCookie.getURI()))
&& (cookie.getName().equals(existingCookie
.getName()))) {
cache.remove(existingCookie);
break;
}
}
System.out.println("Adding to cache: " + cookie);
cache.add(cookie);
}
}
}
public void print() {
System.out.println("Cache: " + cache);
}
public void remove(String name) {
for (Cookie existingCookie : cache) {
if (name.equals(existingCookie.getName())) {
System.out.println("Remove from cache: " + existingCookie);
cache.remove(existingCookie);
break;
}
}
}
public void put(URI uri, String value) {
print();
Cookie cookie = new Cookie(uri, value);
for (Cookie existingCookie : cache) {
if ((cookie.getURI().equals(existingCookie.getURI()))
&& (cookie.getName().equals(existingCookie
.getName()))) {
cache.remove(existingCookie);
break;
}
}
System.out.println("Adding to cache: " + cookie);
cache.add(cookie);
}
/**
* Gets all the applicable cookies from a cookie cache for the specified uri
* in the request header.
*
* @param uri
* URI to send cookies to in a request
* @param requestHeaders
* Map from request header field names to lists of field values
* representing the current request headers
* @return Immutable map, with field name "Cookie" to a list of cookies
*/
public Map
Map
// Retrieve all the cookies for matching URI
// Put in comma-separated list
StringBuilder cookies = new StringBuilder();
for (Cookie cookie : cache) {
// Remove cookies that have expired
if (cookie.hasExpired()) {
cache.remove(cookie);
} else if (cookie.matches(uri)) {
if (cookies.length() > 0) {
cookies.append("; ");
}
cookies.append(cookie.toString());
}
}
// Map to return
Map
requestHeaders);
// Convert StringBuilder to List, store in map
if (cookies.length() > 0) {
List
cookieMap.put("Cookie", list);
}
System.out.println("Cookies: " + cookieMap);
return Collections.unmodifiableMap(cookieMap);
}
}