Проблема может быть решена следующим образом. В приведенном ниже коде мы извлекаем «JSESSION» и «SOME_COOKIE», два файла cookie, которые приходят с сервера, использующего тот же заголовок «set-cookie».
String sessionID = "";
String someCookie = "";
String headerKey = "";
int indexField = 0;
while((headerKey = httpConnection.getHeaderFieldKey(indexField)) != null){
String headerValue = httpConnection.getHeaderField(indexField);
if(headerKey.equals("set-cookie")){
//do something with the string
if(headerValue.indexOf("JSESSION")>=0){//if "JSESSION" is present in the String
sessionID = headerValue.substring(0, headerValue.indexOf(";"));
}
if(headerValue.indexOf("SOME_COOKIE")>=0){//if "SOME_COOKIE" is present in the String
someCookie = headerValue.substring(0, headerValue.indexOf(";"));
}
}
indexField++;
}