0
我已成功登錄並收到會話Cookie。現在我需要在另一個URL的Header中傳遞此會話cookie以獲取更多信息。網址:http://myexperiment.org.uk/whoami.xml然後應該重定向到另一個生成XML樹的URL。我需要使用這個XML來獲取用戶ID信息(這是一個樹節點)。在URL標頭中傳遞會話Cookie
這是我的代碼。
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。
希望有人能幫到這裏。
在此先感謝。