Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apache-httpclient-get-with-body #184

Open
v5tech opened this issue Aug 31, 2018 · 0 comments
Open

apache-httpclient-get-with-body #184

v5tech opened this issue Aug 31, 2018 · 0 comments

Comments

@v5tech
Copy link
Owner

v5tech commented Aug 31, 2018

https://stackoverflow.com/questions/12535016/apache-httpclient-get-with-body

HttpGetWithEntity.java

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpGet;

import java.net.URI;

public class HttpGetWithEntity extends HttpEntityEnclosingRequestBase {

    public HttpGetWithEntity() {
        super();
    }

    public HttpGetWithEntity(URI uri) {
        super();
        setURI(uri);
    }

    public HttpGetWithEntity(String uri) {
        super();
        setURI(URI.create(uri));
    }

    @Override
    public String getMethod() {
        return HttpGet.METHOD_NAME;
    }
}

使用方法

HttpGetWithEntity httpGet= new HttpGetWithEntity(url);
HttpEntity httpEntity = new StringEntity(body, ContentType.APPLICATION_JSON);
httpGet.setEntity(httpEntity);
httpClient.execute(httpGet); 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant