编程语言

img Squall_Zhong

J2ME Read Cookies

发表于2004/10/25 17:08:00  742人阅读

分类: 代码

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;
}

阅读全文
0 0

相关文章推荐

img
取 消
img