こんにちは、現在、users.Am を認証するために xml ドキュメントを解析する必要があるアプリケーションに取り組んでいます。java.net.* パッケージの URLConnection クラスを使用して、xml 形式で応答を返す特定の URL として接続しています。jdom を使用してドキュメントを解析しようとすると、次のエラーが発生します。
org.jdom2.input.JDOMParseException: Error on line 1: Premature end of file
誰でも問題を特定して、解決策を教えてもらえますか? ありがとう、ここに私のコードのセクションがあります
try {
String ivyString = "http://kabugi.hereiam.com/?username=" + ivyUsername + "&password=" + ivyPassword;
URL authenticateURL = new URL(ivyString);
URLConnection ivyConnection = authenticateURL.openConnection();
HttpURLConnection ivyHttp = (HttpURLConnection) ivyConnection;
System.out.println("Response code ==>" + ivyHttp.getResponseCode());
if (ivyHttp.getResponseCode() != 200) {
ctx.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Invalid username or password!", ""));
page = "confirm.xhtml";
} else {
BufferedReader inputReader = new BufferedReader(new InputStreamReader(ivyConnection.getInputStream()));
String inline = "";
while ((inline = inputReader.readLine()) != null) {
System.out.println(inline);
}
SAXBuilder builder = new SAXBuilder();
Document document = (Document) builder.build(ivyConnection.getInputStream());
Element rootNode = document.getRootElement();
List list = rootNode.getChildren("data");
for (int i = 0; i < list.size(); i++) {
Element node = (Element) list.get(i);
System.out.println("Element data ==>" + node.getChildText("username"));
System.out.println("Element data ==>" + node.getChildText("password"));
}
page = "home.xhtml";
}
} catch (Exception ex) {
ex.printStackTrace();
// ctx.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Invalid username or password!", ""));
}