根据url获取请求中的cookie

时间:2022-06-22 21:56:29

建立网络连接,
HttpURLConnection conn = (HttpURLConnection) imgUrl.openConnection()
获取getHeaderFields:
Map< String, List> map = conn.getHeaderFields();
再get(“Set-Cookie”):
List cookies = map.get(“Set-Cookie”);
打印出的buf就是.下文中的应用还包含生成Bitmap.

private Bitmap getImageBitmap(String url) {
URL imgUrl = null;
Bitmap bitmap = null;
try {
imgUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) imgUrl.openConnection();
conn.setDoInput(true);
conn.connect();

Map<String, List<String>> map = conn.getHeaderFields();
List<String> cookies = map.get("Set-Cookie");
StringBuffer buf = new StringBuffer();
for (String cookie : cookies) {
buf.append(cookie);
}
System.out.println("segg6575---buf = " + buf.toString());
InputStream is = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(is);
is.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}