從我的Android應用程序,我試圖刪除存儲在tomcat的webapps目錄中的圖像。當我嘗試下面的代碼時,它給了我403個狀態碼。我在網上查詢,發現如果請求是合法的,但該行爲被禁止,它會提供該代碼。誰能告訴我在哪裏,我要去wrong.My代碼:http刪除403錯誤tomcat
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("DELETE");
int responseCode = connection.getResponseCode();
,當我試圖使用HttpClient的,它給了我同樣的錯誤 - HTTP/1.1 403禁止
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();
}