java如何执行HTTP删除?我得到的只是网址 2 周 Questions & Answers 15048 我只是一个java初学者,想知道如何对URL进行HTTP Delete调用。 任何一小段代码或参考资料都会非常有用 我知道这个问题听起来很简单,但我急需这个信息
# 1 楼答案 您还可以尝试ApacheHttpClient,它为所有HTTP方法(GET、PUT、DELETE、POST、OPTIONS、HEAD和TRACE)提供API 查看这里的示例:http://hc.apache.org/httpclient-3.x/methods/delete。 API引用在这里:http://hc.apache.org/httpclient-3.x/apidocs/index.html 干杯
# 2 楼答案 您可以使用Restlet。这是一个很好的客户端API。或者你可以做如下的事情 URL url = new URL("http://www.example.com/resource"); HttpURLConnection httpCon = (HttpURLConnection) url.openConnection(); httpCon.setDoOutput(true); httpCon.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded" ); httpCon.setRequestMethod("DELETE"); httpCon.connect(); httpCon.getInputStream()
# 3 楼答案 DELETE、PUT、OPTIONS方法受大多数服务器的限制。以下是关于SO中此主题的良好讨论。 Are the PUT, DELETE, HEAD, etc methods available in most web browsers?
# 4 楼答案 我想你可以这样称呼: URL url = new URL("http://www.abcd.com/blog"); HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection(); httpConnection.setDoOutput(true); httpConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded" ); httpConnection.setRequestMethod("DELETE"); httpConnection.connect();
# 5 楼答案 实际上发送HttpDelete与HttpGet类似,首先您将使用所有参数构建url,然后只执行请求,测试以下代码 StringBuilder urlBuilder = new StringBuilder(Config.SERVER) .append("/api/deleteInfo?").append("id=") .append(id); urlBuilder.append("&people=").append(people).toString(); try { HttpClient httpClient = new DefaultHttpClient(); HttpDelete httpDelete = new HttpDelete(urlBuilder.toString()); HttpResponse httpResponse = httpClient.execute(httpDelete); HttpEntity entity = httpResponse.getEntity(); final String response = EntityUtils.toString(entity); Log.d(TAG, "content = " + response); } catch (final Exception e) { e.printStackTrace(); Log.d(TAG, "content = " + e.getMessage()); } catch (OutOfMemoryError e) { e.printStackTrace(); System.gc(); }
# 1 楼答案
您还可以尝试ApacheHttpClient,它为所有HTTP方法(GET、PUT、DELETE、POST、OPTIONS、HEAD和TRACE)提供API
查看这里的示例:http://hc.apache.org/httpclient-3.x/methods/delete。 API引用在这里:http://hc.apache.org/httpclient-3.x/apidocs/index.html
干杯
# 2 楼答案
您可以使用Restlet。这是一个很好的客户端API。或者你可以做如下的事情
# 3 楼答案
DELETE、PUT、OPTIONS方法受大多数服务器的限制。以下是关于SO中此主题的良好讨论。 Are the PUT, DELETE, HEAD, etc methods available in most web browsers?
# 4 楼答案
我想你可以这样称呼:
# 5 楼答案
实际上发送HttpDelete与HttpGet类似,首先您将使用所有参数构建url,然后只执行请求,测试以下代码