Skip to content

apache-httpclient-get-with-body #184

@v5tech

Description

@v5tech

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions