简体   繁体   English

来自URL的XML响应在Java中不正确,但在浏览器中正确

[英]XML response from URL not correct in Java, but correct in browser

Firs of all I want to say that I was able to read XML response from URL with the help of Stackoverflow. 首先,我想说我能够借助Stackoverflow从URL读取XML响应。 Thank you for this and many other helps. 感谢您的帮助以及其他许多帮助。 I read and printed the response (code below) but the result is not correct. 我阅读并打印了响应(以下代码),但结果不正确。

In browser shows me (correct): 在浏览器中显示我(正确):

<ENELIT>
<GESI>
<RI>
<NR id="008201dfa306f4a2" tu="N" nr="0412395504" ut="" cp="" dp="" tm="" ca="" da="" rt="" cc="4"/>
</RI>
</GESI>
</ENELIT>

And in Java it prints this (incorrect): 并在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>

How can I get the correct result? 如何获得正确的结果? Thank you! 谢谢!

My code for getting and printing the response: Example 1: 我用于获取和打印响应的代码:示例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();

Example 2: 范例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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM