gpt4 book ai didi

android - 带正文的 HttpDelete

转载 作者:IT王子 更新时间:2023-10-29 00:00:56 26 4
gpt4 key购买 nike

我正在尝试使用 HttpDelete 对象来调用 Web 服务的删除方法。 Web 服务的代码从消息的正文中解析 JSON。但是,我不明白如何将正文添加到 HttpDelete 对象。有没有办法做到这一点?

使用 HttpPut 和 HttpPost,我调用 setEntity 方法并传入我的 JSON。 HttpDelete 似乎没有任何此类方法。

如果无法为 HttpDelete 对象设置主体,请您将我链接到使用 HttpDelete 父类(super class)的资源,以便我可以设置方法(删除)并设置主体。我知道这并不理想,但此时我无法更改网络服务。

最佳答案

您是否尝试过如下覆盖 HttpEntityEnclosureRequestBase:

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(); }
}

这将创建一个具有 setEntity 方法的 HttpDelete-lookalike。我认为抽象类几乎可以为您完成所有工作,所以这可能就是您所需要的。

FWIW,代码基于 this source to HttpPost that Google turned up .

关于android - 带正文的 HttpDelete,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3773338/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com