Created
February 23, 2017 12:14
-
-
Save r-trigo/1661daca10f9d593a488121c3f0f2b75 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//To perform an HTTP PUT: | |
URL url = new URL("http://www.example.com/resource"); | |
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection(); | |
httpCon.setDoOutput(true); | |
httpCon.setRequestMethod("PUT"); | |
OutputStreamWriter out = new OutputStreamWriter( | |
httpCon.getOutputStream()); | |
out.write("Resource content"); | |
out.close(); | |
httpCon.getInputStream(); | |
//To perform an HTTP DELETE: | |
URL url = new URL("http://www.example.com/resource"); | |
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection(); | |
httpCon.setDoOutput(true); | |
httpCon.setRequestProperty( | |
"Content-Type", "application/x-www-form-urlencoded" ); | |
httpCon.setRequestMethod("DELETE"); | |
httpCon.connect(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment