[英]XML response from URL not correct in Java, but correct in browser
首先,我想說我能夠借助Stackoverflow從URL讀取XML響應。 感謝您的幫助以及其他許多幫助。 我閱讀並打印了響應(以下代碼),但結果不正確。
在瀏覽器中顯示我(正確):
<ENELIT>
<GESI>
<RI>
<NR id="008201dfa306f4a2" tu="N" nr="0412395504" ut="" cp="" dp="" tm="" ca="" da="" rt="" cc="4"/>
</RI>
</GESI>
</ENELIT>
並在Java中顯示以下內容(不正確):
<html>
<head>
<link rel=stylesheet href="/psiche/styles/IEStyle.css" type="text/css">
</head>
<body>
<SCRIPT FOR=window EVENT=onload LANGUAGE="JAVAScript">
if (top.areaApplication != undefined)
{
alert("Sessione utente scaduta. Effettuare il logon");
top.areaApplication.location = "/gesi/online/root/login.htm";
}
</SCRIPT>
<h2>Sessione scaduta, Effettuare il logon.</h2>
</body>
</html>
如何獲得正確的結果? 謝謝!
我用於獲取和打印響應的代碼:示例1:
URL url = new URL("http://gesi-ro-test.banat.enelro:8010/dynamic/gesi/ri/elab/phonerequest/wind.serid=008201dfa306f4a2&nr=06648624&is=2011/04/20%2013:03:03.296&rt=RE/");
BufferedReader in = new BufferedReader(
new InputStreamReader(url.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
范例2:
URL url = new URL("http://gesi-ro-test.banat.enelro:8010/dynamic/gesi/ri/elab/phonerequest/wind.ser?id=008201dfa306f4a2&nr=06648624&is=2011/04/20%2013:03:03.296&rt=RE");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
InputStream stream = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
StringBuilder sb = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null)
{
sb.append(line).append("\n");
}
stream.close();
System.out.println(sb.toString());
在不使用特定語言的情況下,似乎您必須先登錄服務才能訪問信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.