Hi,
I have a client program in which i make a HTTPURLConnection to a RESTful web service. I am passing all XML data in the http request object. Everything seems to work fine for the HTTP POST/PUT method but not for the DELETE method.
-----------------ADD record via POST Request method ------------------
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
//set request method
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/xml");
connection.setDoOutput(true);
//pass the xml data
PrintWriter writer = new PrintWriter(connection.getOutputStream());
writer.write(xmlData);
writer.flush();
When i execute the following code to delete a record, I am running into this exception...
Exception in
thread "main" java.net.ProtocolException: HTTP method DELETE doesn't support output at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:851)
---------------Delete record via DELETE Request method ------------------
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
//set request method
connection.setRequestMethod("DELETE");
connection.setRequestProperty("Content-Type", "application/xml");
connection.setDoOutput(true);
//pass the xml data
PrintWriter writer = new PrintWriter(
connection.getOutputStream);
writer.write(xmlData);
writer.flush();
I understand the exception it's throwing but how can i still pass the XML data in the request object for which i want to set the request method to be DELETE.
Any inputs or suggestions on this? Appreciate your response. Thanks!