【问题标题】:HTTPDelete Android [duplicate]HTTPDelete Android [重复]
【发布时间】:2016-01-01 17:58:27
【问题描述】:
我有一个要求,我需要将 JSON 数据发送到 HTTPDelete。没有用于删除的 setEntity()。
HttpClient httpClient = new DefaultHttpClient();
HttpDelete httpDel = new HttpDelete(DEL_URL);
StringEntity se = new StringEntity(jsonobj.toString());
//Couldnt set entity.
httpDelReq.setEntity(se);
有没有办法将 JSON 数据发送到服务器
【问题讨论】:
标签:
android
json
http-delete
【解决方案1】:
此链接可以帮助您:
HttpDelete with body
这将创建一个具有 setEntity 方法的 HttpDelete-lookalike。我认为抽象类几乎可以为您完成所有工作,因此这可能就是您所需要的。
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import java.net.URI;
import org.apache.http.annotation.NotThreadSafe;
@NotThreadSafe
class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase {
public static final String METHOD_NAME = "DELETE";
public String getMethod() { return METHOD_NAME; }
public HttpDeleteWithBody(final String uri) {
super();
setURI(URI.create(uri));
}
public HttpDeleteWithBody(final URI uri) {
super();
setURI(uri);
}
public HttpDeleteWithBody() { super(); }
}