我知道要向网络发送 POST 请求,我可以使用以下语法:
HttpPost post = new HttpPost(api_address);
String response = null;
int status_code = -1;
StringEntity se = new StringEntity(json_data, HTTP.UTF_8);
se.setContentType("application/json");
// Set entity
post.setEntity(se);
但是,DELETE 不存在 setEntity 方法。那么发送带有数据的 DELETE 的替代方法是什么?
我看了一下:HttpDelete with body
但我真的不明白......我只是一个初学者!
最佳答案
您可以使用 HttpDelete with body 中提供的解决方案像这样:
HttpDeleteWithBody delete = new HttpDeleteWithBody(api_address);
StringEntity se = new StringEntity(json_data, HTTP.UTF_8);
se.setContentType("application/json");
delete.setEntity(se);
关于java - 使用java对api地址和json数据执行HTTP DELETE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14321051/