public String getClientCookies() throws Exception {
/*
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://10.11.77.18:1230/count");
Header[] myheader=httpPost.getAllHeaders();
StringBuffer sb = new StringBuffer();
for (int i=0;i<myheader.length;i++){
sb.append(myheader[i]);
System.out.println(myheader[i]);
}
//sb.toString();
System.out.println(httpPost.getAllHeaders());
//return httpPost.getAllHeaders().toString();
return sb.toString();*/
URL url=new URL("http://10.11.77.18:1230/count");
HttpURLConnection huc= (HttpURLConnection) url.openConnection();
InputStream is = huc.getInputStream();
// 取得sessionID.
String cookieVal = huc.getHeaderField("Set-Cookie");
String sessionId="1";
if(cookieVal != null)
{
sessionId = cookieVal.substring(0, cookieVal.indexOf(";"));
return sessionId;
}
return sessionId;
java 客户端直接读取Cookies
最新推荐文章于 2024-06-28 16:59:20 发布