From my android application, I am trying to delete an image that is stored in the tomcat's webapps directory. When I try the following code its giving me 403 status code. I looked up online and found it gives that code if the request is legal but the action is forbidden. Can anybody tell me where I am going wrong.My code is:
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("DELETE");
int responseCode = connection.getResponseCode();
and when I tried using HttpClient, it gave me the same error- HTTP/1.1 403 Forbidden
HttpClient httpClient = new DefaultHttpClient();
try {
httpClient.getParams().setParameter(
"http.socket.timeout", new Integer(90000));
HttpDelete delete = new HttpDelete(new URI(
"http://192.168.2.1:9090/LocationUpdaterServlet/images/"
+ userid));
Toast.makeText(Image.this, "Removing your picture", 5000).show();
HttpResponse response = httpClient.execute(delete);
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
System.out.println(response.getStatusLine());
} else {
// Here every thing is fine.
}
HttpEntity resEntity = response.getEntity();
if (resEntity == null)
System.out
.println("---------Error No Response !!!-----");
}catch (Exception ex) {
System.out.println("---------Error----"+ ex.getMessage());
ex.printStackTrace();
} finally {
httpClient.getConnectionManager().shutdown();
}