Apache HttpClient GET with body

后端 未结 4 1578
没有蜡笔的小新
没有蜡笔的小新 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-06 00:07

    In addition torbinsky's answer, you can add these constructors to the class to make it easier to set the uri:

    public HttpGetWithEntity(String uri) throws URISyntaxException{
        this.setURI(new URI(uri));
    }
    
    public HttpGetWithEntity(URI uri){
        this.setURI(uri);
    }
    

    The setURI method is inherited from HttpEntityEnclosingRequestBase and can also be used outside the constructor.

提交回复
热议问题