Question

I am getting a HTTP response code 405 when I use HttpURLConnection to make a DELETE request:

  public void makeDeleteRequest(String objtype,String objkey)
{
    URL url=null;
    String uri="http://localhost:8180/GoogleMapsLoadingTest/rest/GoogleMapsErp/";
    HttpURLConnection conn=null;
    try {
        url=new URL(uri);
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        conn=(HttpURLConnection) url.openConnection();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    conn.setDoInput(true);
    conn.setDoOutput(true);
    try {
        System.out.println(conn.getResponseCode());
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    try {
        conn.setRequestMethod("DELETE");
    } catch (ProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

How can I make this request?

Was it helpful?

Solution 2

It would appear to be a problem with your server. I'm guessing nginx, but let me know if not. Take a look here to see how to compile ngninx with HttpDavModule. There are other servers that have issues with this, but nginx doesn't have it by default.

If you're running Apache, check your module configurations to see if you're disallowing them or not. Here's a post about a previous solution. Unfortunately, this problem is typically specific to modules that have been installed. On a vanilla installation, however, you can often just allow for DELETE (see your config file, as well as the OP of that link)

OTHER TIPS

The 405 status code means that your method (DELETE) is not allowed for the resource you specified; in this case, what looks like an entire REST endpoint directory. You should use DELETE on the specific item you want deleted; perhaps you forgot to actually use the method parameters when constructing the URL?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top