【发布时间】:2012-03-17 11:35:03
【问题描述】:
我已成功登录并收到 Session Cookie。现在我需要在另一个 URL 的 Header 中传递这个会话 cookie 以获取更多信息。 URL:http://myexperiment.org.uk/whoami.xml 然后应该将自己重定向到另一个生成 XML 树的 URL。我需要使用这个 XML 来获取用户 ID 信息(这是一个树节点)。
这是我的代码。
Log.d("Session Cookie: ", cookieValue);
URL urlWhoAmI = new URL("http://www.myexperiment.org/whoami.xml");
connection1 = (HttpURLConnection) urlWhoAmI.openConnection();
connection1.setRequestProperty("Set-Cookie", cookieValue);
connection1.connect();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(urlWhoAmI.openStream()));
doc.getDocumentElement().normalize();
NodeList nodeList1 = doc.getElementsByTagName("user");
for(int i=0; i < nodeList1.getLength(); i++)
{
Node node = nodeList1.item(i);
//For user id
Element firstElement = (Element) node;
NodeList nameList = firstElement.getElementsByTagName("id");
Element nameElement = (Element) nameList.item(0);
nameList = nameElement.getChildNodes();
String userID = nameList.item(0).getNodeValue();
Log.d("User ID: ", userID);
}
当我进行调试时,我得到了 url 的 java.io.FileNotFoundException。
希望有人可以在这里提供帮助。
提前致谢。
【问题讨论】:
标签: android session-cookies android-xml sessionid http-redirect