Android HttpURLConnection Delete不';我不能在安卓系统中工作
我想从Android中的RESTful Web服务中删除一个项目。我的Web服务如下所示:Android HttpURLConnection Delete不';我不能在安卓系统中工作,android,httpurlconnection,Android,Httpurlconnection,我想从Android中的RESTful Web服务中删除一个项目。我的Web服务如下所示: @DELETE @Path("/schueler/{id}") @Produces(MediaType.APPLICATION_JSON) public void deleteSchueler(@PathParam("id") int id) { ManagementDAO.instance.deleteSchueler(id); } 下面是一些Android代码。首先调用异步任务: new A
@DELETE
@Path("/schueler/{id}")
@Produces(MediaType.APPLICATION_JSON)
public void deleteSchueler(@PathParam("id") int id) {
ManagementDAO.instance.deleteSchueler(id);
}
下面是一些Android代码。首先调用异步任务
:
new AsyncDeleteSchueler(getApplicationContext()).execute("http://" + url.getText().toString() + ":8080/A07_Webservice/rest/ManagementService/schueler/" + Integer.parseInt(deleteId.getText().toString()));
以及此任务的代码:
public String putJSONToWebservice(String u) {
int responseCode = 0;
try {
URL url = new URL(u);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("DELETE");
connection.setDoOutput(true);
connection.setReadTimeout(10000);
connection.setConnectTimeout(15000);
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept", "application/json");
connection.connect();
responseCode = connection.getResponseCode();
} catch(Exception ex) {
ex.printStackTrace();
}
return Integer.toString(responseCode);
}
你知道为什么
Delete方法不起作用吗?PUT、POST等工作正常,但此代码不起作用。我认为删除是通过POST请求处理的。你有你使用的API的文档吗?API的错误响应是什么?日志中应该有错误