aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes cannot get response!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "cannot get response!!!" Watch "cannot get response!!!" New topic
Author

cannot get response!!!

subho saha
Ranch Hand

Joined: Jun 15, 2005
Posts: 57
I am tring to get the response to a certain web page. I have tracked the request and response from the following page using http analyser. Its sending some kind of XML data with the post request. I have built a code that sends the same request, but getting error.perhaps the problem is with the format in which the xml data is send. Please , please do suggest.

I have attached correct request and response found out through http analyser along with the code down it.

Request
==========================================================
POST /securevault/reservations/canadcorp/srs/step2.php HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Host: www.novgroup.com
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
Cache-Control: no-cache
Connection: Keep-Alive
Content-Length: 609
Content-Type: text/xml

<wddxPacket version="1.0"><header /><data><struct><var name="parameters"><struct><var name="discount"><array length="5"><null /><null /><null /><null /><null /></array></var><var name="enddate"><string>Jul 13, 2006</string></var><var name="startdate"><string>Jul 12, 2006</string></var><var name="hotelid"><string>10</string></var><var name="roomid"><string>40</string></var><var name="adults"><number>1</number></var><var name="fields"><array length="2"><string>id</string><string>name</string></array></var></struct></var><var name="funcName"><string>getRoomPrice</string></var></struct></data></wddxPacket>


==========================================================
Response which is comming.
==========================================================
<wddxPacket version='1.0'><header/><data><struct><var name='cNames'><array length='2'><string>adate</string><string>rate</string></array></var><var name='rates'><array length='1'><array length='2'><string>2006-07-12</string><string>109.00</string></array></array></var></struct></data></wddxPacket>
============================================================================================================================


My code to get the response page
===========================
import java.net.*;
import java.io.*;
import java.net.HttpURLConnection.*;



public class testpost{

public static void main(String[] args) throws Exception {


URL downeyjrURL = new URL("https://www.novgroup.com/securevault/reservations/canadcorp/srs/step2.php");
HttpURLConnection c = (HttpURLConnection)(downeyjrURL.openConnection());
c.setDoOutput(true);
c.setRequestMethod("POST");
PrintWriter out = new PrintWriter(c.getOutputStream());
String xmlString;

String htmlString = "<wddxPacket version=1.0><header /><data><struct><var name=parameters><struct><var name=discount><array length=5><null /><null /><null /><null /><null /></array></var><var name=enddate><string>Jun 23, 2006</string></var><var name=startdate><string>Jun 22, 2006</string></var><var name=hotelid><string>10</string></var><var name=roomid><string>38</string></var><var name=adults><number>1</number></var><var name=fields><array length=2><string>id</string><string>name</string></array></var></struct></var><var name=funcName><string>getRoomPrice</string></var></struct></data></wddxPacket>";

// Here's whether the parameter is set.
out.println("xmldoc=" + URLEncoder.encode(htmlString));
//out.println("xmldoc=" + htmlString);
out.close();

BufferedReader in2 = new BufferedReader(new
InputStreamReader(c.getInputStream()));

String inputLine;
while((inputLine = in2.readLine()) != null)
System.out.println(inputLine);
in2.close();
}
}
//====================================================================================================================
but is giving error --no function called (). I think I am not able tosend the Xml in Right format.Exact error-----------------------------------------------------------------------------------------------------------------------------------------------

br />
<b>Notice</b>: Undefined index: HTTP_RAW_POST_DATA in <b>/var/www/htdocs/novgr
oup.com/securevault/reservations/canadcorp/srs/step2.php</b> on line <b>27</b><b
r />
<br />
<b>Notice</b>: Undefined variable: HTTP_RAW_POST_DATA in <b>/var/www/htdocs/no
vgroup.com/securevault/reservations/canadcorp/srs/step2.php</b> on line <b>30</b
><br />
<br />
<b>Fatal error</b>: Call to undefined function: () in <b>/var/www/htdocs/novgr
oup.com/securevault/reservations/canadcorp/srs/step2.php</b> on line <b>42</b><b
r />


//==================================================================================================================
Please help me. any code or suggestion will be helpful.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

You didn't set the content-type of the request to text/xml, and I don't understand why you're adding the "xmldoc=" to the beginning of the XML you're sending; I don't see that in the request. That would be appropriate for a www-form-urlencoded content type, but not for this SOAP message. Finally, you've stripped all the quotes out of the XML you're sending, making it invalid XML. You could change the double quotes to single quotes, but you must include quotes of some kind!


[Jess in Action][AskingGoodQuestions]
subho saha
Ranch Hand

Joined: Jun 15, 2005
Posts: 57
Hello Ernest, According to your suggestion I modified the code as shown below, but same error as before seems to come. Please make some suggestion.


CODE NOW
===========================================================================

import java.net.*;
import java.io.*;
import java.net.HttpURLConnection.*;



public class testpost
{

public static void main(String[] args) throws Exception {



URL downeyjrURL = new URL("https://www.novgroup.com/securevault/reservations/canadcorp/srs/step2.php");
HttpURLConnection c = (HttpURLConnection)(downeyjrURL.openConnection());
c.setDoOutput(true);
c.setRequestMethod("POST");
PrintWriter out = new PrintWriter(c.getOutputStream());


// Here's where the parameter is set.
out.println("Content-type: text/xml");
//out.println(htmlString);
out.println("<wddxPacket version=\"1.0\">");
out.println("<header />");
out.println("<data>");
out.println("<struct>");
out.println("<var name=\"parameters\">");
out.println("<struct>");
out.println("<var name=\"discount\"><array length=\"5\"><null /><null /><null /><null /><null /></array></var>");
out.println("<var name=\"enddate\"><string>Jul 13, 2006</string></var>");
out.println("<var name=\"startdate\"><string>Jul 12, 2006</string></var>");
out.println("<var name=\"hotelid\"><string>10</string></var>");
out.println("<var name=\"roomid\"><string>40</string></var>");
out.println("<var name=\"adults\"><number>1</number></var>");
out.println("<var name=\"fields\"><array length=\"2\"><string>id</string><string>name</string></array></var>");
out.println("</struct>");
out.println("</var>");
out.println("<var name=\"funcName\"><string>getRoomPrice</string></var>");
out.println("</struct>");
out.println("</data>");
out.println("</wddxPacket>");
out.close();

BufferedReader in2 = new BufferedReader(new
InputStreamReader(c.getInputStream()));

String inputLine;
while((inputLine = in2.readLine()) != null)
System.out.println(inputLine);
in2.close();
}
}
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

You need to use HttpURLConnection.setRequestMethod() to set the Content-type header; do this before you call getOutputStream. And don't use PrintWriter, as it will send line endings appropriate to the local platform; better to manually insert \r\n characters when and if they are needed.
subho saha
Ranch Hand

Joined: Jun 15, 2005
Posts: 57
Thanks Ernest very much. Because of your ideas I changed the code and now its working perfectly.Thank You Very much.

Here is the code which worked Ok.
==============================================================

import java.net.*;
import java.io.*;
import java.net.HttpURLConnection.*;



public class testpost2 extends Object
{

public static void main(String[] args) throws Exception {


URL downeyjrURL = new URL("https://www.novgroup.com/securevault/reservations/canadcorp/srs/step2.php");
URLConnection c = downeyjrURL.openConnection();
//c.setRequestMethod("POST");
c.setDoOutput(true);
c.setDoInput(true);
c.setUseCaches(false);



c.setRequestProperty("User-Agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
c.setRequestProperty("Content-type",
"text/xml");

c.setRequestProperty("soapaction",
"\"http://tempuri.org/ObtenerImporte\"");
c.setRequestProperty("Host",
"www.novgroup.com");


DataOutputStream outStream = new DataOutputStream(
c.getOutputStream());


outStream.writeBytes("<wddxPacket version=\"1.0\">");
outStream.writeBytes("<header />");
outStream.writeBytes("<data>");
outStream.writeBytes("<struct>");
outStream.writeBytes("<var name=\"parameters\">");
outStream.writeBytes("<struct>");
outStream.writeBytes("<var name=\"discount\"><array length=\"5\"><null /><null /><null /><null /><null /></array></var>");
outStream.writeBytes("<var name=\"enddate\"><string>Jul 13, 2006</string></var>");
outStream.writeBytes("<var name=\"startdate\"><string>Jul 12, 2006</string></var>");
outStream.writeBytes("<var name=\"hotelid\"><string>10</string></var>");
outStream.writeBytes("<var name=\"roomid\"><string>38</string></var>");
outStream.writeBytes("<var name=\"adults\"><number>1</number></var>");
outStream.writeBytes("<var name=\"fields\"><array length=\"2\"><string>id</string><string>name</string></array></var>");
outStream.writeBytes("</struct>");
outStream.writeBytes("</var>");
outStream.writeBytes("<var name=\"funcName\"><string>getRoomPrice</string></var>");
outStream.writeBytes("</struct>");
outStream.writeBytes("</data>");
outStream.writeBytes("</wddxPacket>");


outStream.close();
BufferedReader in2 = new BufferedReader(new
InputStreamReader(c.getInputStream()));

String inputLine;
while((inputLine = in2.readLine()) != null)
System.out.println(inputLine);
in2.close();
}
}
[ April 21, 2006: Message edited by: subho saha ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: cannot get response!!!
 
Similar Threads
Image loading problem
Nested members in XML-RPC
SCWCD Exam Simulator
Problem regarding redirected error message
Is it possible to call a servlet function using JavaScript?