get Cookie from HTTP Header - Android Network

Android examples for Network:Cookie

Description

get Cookie from HTTP Header

Demo Code


//package com.java2s;

public class Main {
    public static final String COOKIE_KEY = "JSESSIONID";

    private static String getCookie(String headerString) {
        String cookieValue = null;
        if (headerString != null) {
            int keyIndex = headerString.indexOf(COOKIE_KEY);
            if (keyIndex >= 0) {
                int endIndex = headerString.indexOf(";", keyIndex);
                if (endIndex > keyIndex) {
                    cookieValue = headerString.substring(keyIndex
                            + COOKIE_KEY.length() + 1, endIndex);
                }/*from   ww w  . j a  v  a  2 s.c  o m*/
            }
        }
        return cookieValue;
    }
}

Related Tutorials