Apache HttpClient GET with body

后端 未结 4 1572
没有蜡笔的小新
没有蜡笔的小新 2020-12-05 23:45

I am trying to send an HTTP GET with a json object in its body. Is there a way to set the body of an HttpClient HttpGet? I am looking for the equivalent of HttpPost#setEntit

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-05 23:53

    Using torbinsky's answer I created the above class. This lets me use the same methods for HttpPost.

    import java.net.URI;
    
    import org.apache.http.client.methods.HttpPost;
    
    public class HttpGetWithEntity extends HttpPost {
    
        public final static String METHOD_NAME = "GET";
    
        public HttpGetWithEntity(URI url) {
            super(url);
        }
    
        public HttpGetWithEntity(String url) {
            super(url);
        }
    
        @Override
        public String getMethod() {
            return METHOD_NAME;
        }
    }
    

提交回复
热议问题