From my Android application, I am trying to delete an image that is stored in the tomcat webapps directory. When I try the following code, it gives me the status code 403. I looked online and found that it gives this code if the request is legal, but the action is prohibited. Can someone 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 {
}
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();
}
source
share