我必须使用id从List中删除数据,但我不知道如何进行删除调用。 我必须使用HttpDelete或其他什么?
我在hurl.it上查看了我的删除服务。 它工作正常,但从设备我无法调用删除服务..
HttpClient httpclient = new DefaultHttpClient();
HttpDelete httpdelete = new HttpDelete(url);
hp.setParameter("X-API-KEY","sdgdnjtn@#GBTGH");
hp.setParameter("i_id","10");
httpdelete.setParams(hp);
HttpResponse response = httpclient.execute(httpdelete);
答案 0 :(得分:0)
public static String yourMethod(String url) {
String result = "";
try {
int TIMEOUT_MILLISEC = 100000; // = 10 seconds
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams,TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);
HttpClient httpClient = new DefaultHttpClient();
HttpDelete httpDelete=new HttpDelete(url);
HttpResponse httpResponse = httpClient.execute(httpDelete);
InputStream is = httpResponse.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
} catch (Exception e) {
e.printStackTrace();
return null;
}
return result;
}