AndrewChandler
Programmer
I'm trying to build an XML client which communicates over http with a remote server, using the HttpURLConnection class, but believe that there are problems in the way I am POSTing the data or trying to read the response. The current code is
Can someone point me in the right direction?
Code:
try {
String xml = BuildXML();
byte data [] = xml.getBytes();
URL url = new URL( "[URL unfurl="true"]http://myhost/XMLserver/default.asp"[/URL] );
HttpURLConnection urlcon = (HttpURLConnection)url.openConnection();
urlcon.setRequestMethod("POST");
urlcon.setRequestProperty( "Content-Type", "text/xml" );
urlcon.setRequestProperty( "Content-Lanuguage", "en-US" );
urlcon.setDoInput( true );
urlcon.setDoOutput( true );
urlcon.connect();
OutputStream os = urlcon.getOutputStream();
os.write(data);
os.close();
/* line is used by the paint method */
/* line = "Response = " + urlcon.getResponseMessage(); */
line = "Response = " + urlcon.getContent();
}
catch (Exception e)
{
e.printStackTrace();
}
}
Can someone point me in the right direction?