java - How to send PUT, DELETE HTTP request in HttpURLConnection? -
I want to know if it is possible to send PUT, request via java.net.HttpURLConnection ( Practically) Delete
for HTTP-based URLs.
I have read several articles describing how to send, post, trace, option requests but I still have not found any sample code which successfully executes and delete requests
to an HTTP PUT:.
URL Url = New URL ("http://www.example.com/resource"); HttpURL connection httpCon = (HttpURLConnection) url.openConnection (); HttpCon.setDoOutput (true); HttpCon.setRequestMethod ("put"); OutputStreamWriter = New OutputStreamWriter (httpCon.getOutputStream ()); Out.written ("resource content"); Out.close (); HttpCon.getInputStream ();
To delete an HTTP:
URL url = new URL ("http://www.example.com/resource"); HttpURL connection httpCon = (HttpURLConnection) url.openConnection (); HttpCon.setDoOutput (true); HttpCon.setRequestProperty ("content-type", "app / x-www-form-urxed"); HttpCon.setRequestMethod ("Delete"); HttpCon.connect ();
Comments
Post a Comment