I need to send an xml request to a web service and accept xml response from that web service.
Below is the Code:
public static void main(String[] args) throws IOException {
String url ="http://XX.XXX.X.XX:80/test";
String urlParameters = "";
StringBuilder test = new StringBuilder(768);
test.append("<?xml version='1.0'?>\n"+
"<!DOCTYPE COMMAND PUBLIC '-//Ocam//DTD XML Command 1.0//EN' 'xml/command.dtd'>\n"+
"<COMMAND>\n"+
"<TYPE>EXUSRBALREQ</TYPE>\n"+
"<DATE>14-03-17</DATE>\n"+
"<EXTNWCODE>MD</EXTNWCODE>\n"+
"<MSISDN>57625960</MSISDN>\n"+
"<PIN>47565</PIN>\n"+
"<LOGINID></LOGINID>\n"+
"<PASSWORD></PASSWORD>\n"+
"<EXTCODE>AD10001</EXTCODE>\n"+
"<EXTREFNUM>12345</EXTREFNUM>\n"+
"</COMMAND>\n");
System.out.println(test);
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content_Type", "application/xml");
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
System.out.println("Sending post on the URL"+url);
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream(),"UTF-8"));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(responseCode);
System.out.println(response);
}
Whenever i run the application i am getting 200 status however below is the response which i get
Response:
Sending post on the URLhttp://XXX.XXX.X.XX:80/test
200
mclass^2&pid^61:6002:Your request is invalid. Please call 8900
Can Somebody help me with this.
Regards,
Amit Gupta