• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

DELETE http request in HttpURLConnection....

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!


 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What would that XML data be for? The resource is indicated by the URL, and the operation is to delete it. There's no need for further data.
 
Vim Shir
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The xml data has details like which record (record's id, name, etc) to delete etc.,

This is what i am doing ....

In RESTful web service when i get the xml data in the http request object, i insert the data into a load table first & then call the stored proc to insert the data into the main table which updates the status flag in the load table as successful insert/update/delete/error etc., Then, i fetch the status flag info and send the response back to the client as record was inserted/updated/deleted.

Inserts and updates are working fine but not the delete part. Any further suggestions on this?

Thanks and appreciate your response.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's not how HTTP DELETE -and by extension, a purely RESTful design- works. It sounds as if you'd be better off using a POST.
 
We find this kind of rampant individuality very disturbing. But not this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic