olá pessoal!
Estive pesquisando e to testando esse código que achei na net, pra pegar o valor do cookies.
Só que na linha String headerValue = conn.getHeaderField(i), ele ta retornando um valor:
JSESSIONID= 748659DCA7458T5678VF
O problema é que eu queria pegar o valor mesmo, tipo usuario ou senha e nao essa string.
Alguém poderia me ajudar?
Obrigada!
try {
// Create a URLConnection object for a URL
URL url = new URL(“<a href="http://localhost:8080/Oficializa/">http://localhost:8080/Oficializa/</a>”);
URLConnection conn = url.openConnection();
// Get all cookies from the server.
// Note: The first call to getHeaderFieldKey() will implicit send
// the HTTP request to the server.
for (int i=0; ; i++) {
String headerName = conn.getHeaderFieldKey(i);
String headerValue = conn.getHeaderField(i);
if (headerName == null && headerValue == null) {
// No more headers
break;
}
if ("Set-Cookie".equalsIgnoreCase(headerName)) {
// Parse cookie
String[] fields = headerValue.split(";\\s*");
String cookieValue = fields[0].toString();
String expires = null;
String path = null;
String domain = null;
boolean secure = false;
// Parse each field
for (int j=1; j<fields.length; j++) {
if ("secure".equalsIgnoreCase(fields[j])) {
secure = true;
} else if (fields[j].indexOf('=') > 0) {
String[] f = fields[j].split("=");
if ("expires".equalsIgnoreCase(f[0])) {
expires = f[1];
} else if ("domain".equalsIgnoreCase(f[0])) {
domain = f[1];
} else if ("path".equalsIgnoreCase(f[0])) {
path = f[1];
}
}
}
// Save the cookie...
}
}
} catch (MalformedURLException e) {
} catch (IOException e) {
}
