XML response correct in broser but incorrect in Java

XML response correct in broser but incorrect in Java

Firs of all I want to say that I was able to read XML response from URL. 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):

<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:

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:

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());
View Answers

August 22, 2012 at 4:48 PM

I just saw your thread and analysed your problem you are facing. I suggest that your browser is cooperating with the server in maintaining a session, most likely by receiving and sending a cookie. Your Java code should do the same thing. So first it should go to the login page with the right parameters, and then it should receive a cookie along with the response, and then it should go to the data page, sending the cookie along with the data.









Related Tutorials/Questions & Answers:
XML response correct in broser but incorrect in Java
XML response correct in broser but incorrect in Java  Firs of all I want to say that I was able to read XML response from URL. Thank you...;/ENELIT> And in Java it prints this (incorrect): <html> <head>
Identify correct and incorrect statements or examples about EJB programming restrictions.
Identify correct and incorrect statements or examples about EJB... Overview Next     Identify correct and incorrect statements... that the security rules of the Java programming language make unavailable. ADS
Advertisements
Identify correct and incorrect statements or examples about the purpose and use of EJB QL.
Identify correct and incorrect statements or examples about...;Next    Identify correct and incorrect statements...;Home Identify correct and incorrect conditional expressions, BETWEEN
Identify correct and incorrect statements or examples about the client view of a entity bean's remote component interface (EJBObject).
Identify correct and incorrect statements or examples about...;   Identify correct and incorrect statements or examples about...;NextIdentify correct and incorrect statements or examples about the client view
Identify correct and incorrect statements or examples about the client view of an entity bean's local component interface (EJBLocalObject).
Identify correct and incorrect statements or examples about...;   Identify correct and incorrect statements or examples about the client...;Home Identify correct and incorrect statements or examples about the client
Identify correct and incorrect conditional expressions, BETWEEN expressions, IN expressions, LIKE expressions, and comparison expressions.
Identify correct and incorrect conditional expressions...; Identify correct and incorrect conditional expressions...;NextIdentify correct and incorrect statements or examples about the purpose and use
Identify correct and incorrect statements or examples about the client view of a session bean's local and remote component interfaces.
Identify correct and incorrect statements or examples about the client view of a session bean's local and remote component interfaces...;   Identify correct and incorrect statements or examples about
Identify correct and incorrect statements or examples about the client's view of exceptions received from an enterprise bean invocation.
Identify correct and incorrect statements or examples about...; Identify correct and incorrect statements or examples about the client's view... interfaces are both Java RMI interfaces, and therefore the throws clauses
Identify correct and incorrect statements or examples about the rules and semantics for relationship assignment and relationship updating in a CMP bean.
Identify correct and incorrect statements or examples about...;NextIdentify correct and incorrect statements or examples about persistent... for Container-Managed Persistence (CMP) Next     Identify correct
Identify correct and incorrect statements or examples about an entity bean's primary key and object identity.
Identify correct and incorrect statements or examples about.... Entity Beans Next    Identify correct and incorrect statements or examples about an entity bean's primary key and object
Given a security-related deployment descriptor tag, identify correct and incorrect statements and code related to that tag.
correct and incorrect statements and code related to that tag. Prev ...; Given a security-related deployment descriptor tag, identify correct and incorrect statements and code related to that tag
Identify correct and incorrect statements about the Application Assembler's responsibilities, including the use of deployment descriptor elements related to transactions and the identifica
Identify correct and incorrect statements about the Application Assembler's responsibilities, including the use of deployment descriptor elements...; Identify correct and incorrect statements about the Application Assembler's
Free Java Is it correct?
Free Java Is it correct?  Hi, Is Java free? If yes then where I can download? Thanks   Hi, You can download it from http://www.oracle.com/technetwork/java/javase/downloads/index.html Thanks
Produces XML file but format not correct for storing data using JSP and XML
Produces XML file but format not correct for storing data using JSP and XML  hii I have created a project using JSP and XML as database to store data entered by user in XML file ,It stores data entered in XML file
Correct errors - Java Beginners
Correct errors  Identify and correct the errors in the following program: public java Method { public static method1(int n, m) { n += m; xMethod(3. 4); } public static int xMethod(int n) { if (n > 0) return 1
Identify correct and incorrect statements or examples about application exceptions and system exceptions in entity beans, session beans, and message-driven beans.
Identify correct and incorrect statements or examples about application exceptions and system exceptions in entity beans, session beans...;Exceptions Next    Identify correct and incorrect statements
Identify correct and incorrect statements or examples about persistent relationships, remove protocols, and about the abstract schema type of a CMP entity bean.
Identify correct and incorrect statements or examples about...; Identify correct and incorrect statements or examples about persistent... Persistence (CMP) Home Identify correct and incorrect statements or examples
Identify correct and incorrect statements about the purpose and use of the deployment descriptor elements for environment entries, EJB references, and resource manager connection factory r
Identify correct and incorrect statements about the purpose and use... correct and incorrect statements about the purpose and use of the deployment... whether a given code listing is appropriate and correct with respect
Java Servlet : Http Response Headers
Java Servlet : Http Response Headers In this tutorial, you will learn how to Http Response Headers works in java servlet. Http Response Headers : Web server sends response with one or more response headers including the document
How we can integrate ASP .net website to payment gateway using SOAP xml request and response using wsdl.
gateway provider provide us SOAP Xml request and SOAP xml response format along...How we can integrate ASP .net website to payment gateway using SOAP xml request and response using wsdl.  We have a e-commerce website in ASP.net, c
How do I write a correct micro-benchmark in Java?
How do I write a correct micro-benchmark in Java?  How do I write a correct micro-benchmark in Java
XMl and Java web services
XMl and Java web services  I want to do a project on java web services and XML. I wanted to ask, how the data entered by user through the HTML file... and JDBC the response can be sent back to the client? Also, how the XML file can
Java + XML - XML
Java + XML  1) I have some XML files, read one xml... java...the attribute value..not sure now how to read the xml file passing..." pointing to a hello xml file ..read that file and get the value of the parent
java and xml - XML
java and xml  Hi Deepak, I want learn xml and java(applications). Which editor is best usefull(trial--version) in my applications...; Hi friend, http://www.roseindia.net/xml/dom/ Thanks
Java-XML-DOM - XML
Java-XML-DOM  Hi! I need some help. I have to make java program that loads an xml file and from it builds DOM(later i will have to work with it - like using xpath in java find some value and replace it...). Since i'm new to java
java and xml - XML
java and xml   test_final_1 2009-025T13:23:45 B2B I want to validate each tag.. and i don't have any xsd.. kindly help me to solve...://www.roseindia.net/xml/dom/DOMValidateDTD.shtml Thanks
XML with JAVA - XML
document and the processing in JAVA program . Find the time for each XML element...XML with JAVA  Hi.. This is Priya here. Thanks for responding me. I have a query. "Write program in java to evaluate the time to access
java and xml problem - XML
java and xml problem  hi, i need to write a java program that generates an xml file as follows: aaa vvv --------- i have witten a program in java, but im
java with xml
java with xml  Hi i am reading xml data with sax parser in java. ok its fine. But in future xsd and xml will change. now my question is if xsd and XML will change my java progrm will not change. is it possible ? Thanks
java with xml
java with xml  Hi i am reading xml data with sax parser in java. ok its fine. But in future xsd and xml will change. now my question is if xsd and XML will change my java progrm will not change. is it possible ? Thanks
XML in java - XML
XML in java  Write a program using SAX that will count the number of occurrences of each element type in an XML document and display them...://www.roseindia.net/xml/sax/SAXElementCount.shtml Hope that it will be helpful
Read XML in java - XML
Read XML in java  Hi Deepak, I want to read a xml file which have only one element with multiple attributes with same tag name. here is my file... a solution.my java code is given below. import java.io.File; import
java - XML
This is my XML file then how can read this XML file Using DOM & SAX parsers in java? How can write the same data into XML file using DOM parser? Could you
java with xml
java with xml  hi i have a problem. // this sample code is reading xml file in java DefaultHandler handler = new DefaultHandler... xml file change in future then my java code will also change. but is there any
php parse soap response
php parse soap response  What is soap and how can i convert a soap response to XML. Thanks in Advance
java - XML
java  How can write data into XML file using DOM parser? How can convert HTWL file to XML file
java - XML
java  how can i validate my xml file using java code plz send me de... kumar  Hi friend, Step to validate a xml file against a DTD (Document Type Definition) using the DOM APIs. Here is the xml file "User.xml
Java and converting a PDF to XML
Java and converting a PDF to XML  I reviewed your example - https://www.roseindia.net/tutorial/java/xml/pdftoXML.html - and on many users group... getting a response from them.Can you help me out ?? This project is very important
Java and converting a PDF to XML
Java and converting a PDF to XML  I reviewed your example - https://www.roseindia.net/tutorial/java/xml/pdftoXML.html - and on many users group... getting a response from them.Can you help me out ?? This project is very important
XML and java
XML and java  Hi I have xml data in XMLStreamreader object how to retrive tha data and write into a file using java Your help will be much appreciated Thanks   Hi Friend, Try the following code: import java.io.
java - XML
java  How to prepare an xml document by reading data from a table in the database . (the database access logic is written inside the servlet
java - XML
you get the data3. And in the servlet class you can use the DOM api to create xml... it to the xml treedoc.appendChild(root);For more information please visit http://www.roseindia.net/xml/dom/createdomchildelement.shtmlThanks
XML parsing using Java - XML
XML parsing using Java  I'm trying to parse a big XML file in JAVA. The goal is like i will take console input from user until "Coverage" in element "MIRate"(THE XML code is below).once he enters coverage rate I need
java - XML
in the XML document while i am parsing the file using SAX event based parser.... provide the way in java.  Hi Friend, Try the following code: import... parser = parserFact.newSAXParser(); System.out.println("XML Data
Java Xml Data Store
or XML file. As a good Java programmer you will use correct Object-Oriented...Java Xml Data Store  I have to do this project and i'm finding it so hard its way over my head if any one has any ideas or help. What would the best
XML clonning with java and passing arguments
XML clonning with java and passing arguments  Hi, I have a XML file as follows. My requirements are as below. 1. Clone the whole xml file. 2... if 2 then with arguments1 and then arguments2. <?xml version=ââ?¬Â?1.0??>
xml to html via java
xml to html via java  how to read xml into html using java code
diplay response
diplay response   Sir, How show sum of two tex boxes data to third box   Answer (adsbygoogle = window.adsbygoogle || []).push
java - XML
java  How to read the values of XMLStreamConstants.CDATA in simple java
JAVA - XML
JAVA  hi.. i want to talk to any SWT expert in JAVA... how can i do it?   Hi friend, For read more information,Examples and Tutorials on SWT visit to : http://www.roseindia.net/tutorials/swt/ Thanks

Ads