【发布时间】:2012-01-27 18:37:17
【问题描述】:
我正在用 java 构建一些服务,但发现重定向存在一些问题。
我在 domainA 中有登录表单。登录后,我想在其他域 domainB 中设置 cookie。
现在,当我打开 domainA 一段时间后,我想检查 domainB 中是否有 Cookie sen,但我不想重定向用户domainA 到 domainB。
有没有可能,用 JAVA 从 domainA 向 domainB 发送请求以检查是否有任何 Cookie?
我正在尝试:
try {
URL url = new URL(rURL + "checkCookie" );
InputStream response2 = url.openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(response2, "UTF-8"));
for(String line; (line = reader.readLine()) != null;){
responsePool += line;
}
}catch(Exception e2){
e2.printStackTrace();
}
logger.info(responsePool);
在 domainB 中获取 Cookie 的代码就是:
try {
Cookie[] cookies = request.getCookies();
for (int i = 0; i < cookies.length; i++) {
Cookie c = cookies[i];
if (c.getName().equals("xvz")) {
cookieSCS = c.getValue();
}
}
if(cookieSCS == null || cookieSCS == ""){
cookieSCS = "there is no cookie";
}
} catch (Exception e) {
cookieSCS = e.toString();
}
但是我得到java.lang.NullPointerException,我知道这种方法不会给我一个cookie,但是有没有可能从domainB获取cookie而不在domainB中打开浏览器?
【问题讨论】: