Delete resource

suggest change
public static void delete (String urlString, String contentType) throws IOException {
     HttpURLConnection connection = null;
 
     try {
         URL url = new URL(urlString);
         connection = (HttpURLConnection) url.openConnection();
         connection.setDoInput(true);
         connection.setRequestMethod("DELETE");
         connection.setRequestProperty("Content-Type", contentType);
 
         Map<String, List<String>> map = connection.getHeaderFields();
         StringBuilder sb = new StringBuilder();
         Iterator<Map.Entry<String, String>> iterator = responseHeader.entrySet().iterator();
         while(iterator.hasNext())
         {
             Map.Entry<String, String> entry = iterator.next();
             sb.append(entry.getKey());
             sb.append('=').append('"');
             sb.append(entry.getValue());
             sb.append('"');
             if(iterator.hasNext())
             {
                 sb.append(',').append(' ');
             }
         }
         System.out.println(sb.toString());
 
     } catch (Exception e) {
         e.printStackTrace();
     } finally {
         if (connection != null) connection.disconnect();
     }
 }

This will DELETE the resource in the specified URL, then print the response header.

How it works

At last we print the server response header.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents