HttpDelete with body

前端 未结 5 580
孤街浪徒
孤街浪徒 2020-11-28 08:46

I\'m attempting to use an HttpDelete object to invoke a web service\'s delete method. The web service\'s code parses JSON from the message\'s body. However, I\'m failing t

5条回答
  •  佛祖请我去吃肉
    2020-11-28 09:14

    Have you tried overriding HttpEntityEnclosingRequestBase as follows:

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

    That will create a HttpDelete-lookalike that has a setEntity method. I think the abstract class does almost everything for you, so that may be all that's needed.

    FWIW, the code is based on this source to HttpPost that Google turned up.

提交回复
热议问题