J2ME Read Cookies

发表于:2007-07-01来源:作者:点击数: 标签:
private String readCookie( HttpConnection conn ) throws IOException { String key; String value; String[] substrs; for( int i = 0; ( key = conn.getHeaderFieldKey( i ) ) != null; ++i ) { key = key.toLowerCase(); if( key.equals( set-cookie ) )
private String readCookie( HttpConnection conn ) throws IOException {
String key;
String value;
String[] substrs;
for( int i = 0; ( key = conn.getHeaderFieldKey( i ) ) != null; ++i ) {
key = key.toLowerCase();
if( key.equals( "set-cookie" ) ){
value = conn.getHeaderField( i );

while( value != null ) {
substrs = Utils.split( value, @#;@# );
if( substrs[0].startsWith("JSESSIONID=") || // Java
substrs[0].startsWith("PHPSESSID") || // PHP
substrs[0].startsWith("SessionId") // ASP
){
return substrs[0];
}
value = substrs[1];
}
}
}
return null;
}


原文转自:http://www.ltesting.net