我有一个要求,我需要将一个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数据发送到服务器
答案 0 :(得分:0)
此链接可以帮助您: 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(); }
}