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

some bugs #2

Open
terrytomas opened this issue Sep 20, 2017 · 0 comments
Open

some bugs #2

terrytomas opened this issue Sep 20, 2017 · 0 comments

Comments

@terrytomas
Copy link

#public String post(HttpPost request, String postData) throws PostageAppException {
request.addHeader(new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"));
request.addHeader(HttpHeaders.USER_AGENT, this.getUserAgent());

    HttpResponse postResponse;

    try {
    	
    	request.setEntity(new StringEntity(postData));
        postResponse = this.httpClient.execute(request);

        if (postResponse.getStatusLine().getStatusCode() / 100 != 2) {
            throw new PostageAppException("Unable to connect to PostageApp servers for API endpoint " + request.getURI().toString());
        }

        try {
            return IOUtils.toString(postResponse.getEntity().getContent());
        } catch (Exception e) {
            throw new PostageAppException(e.getMessage());
        }
    } catch (Exception e) {
        throw new PostageAppException(e.getMessage());
    } finally {
        if (httpClient != null) {
            request.releaseConnection();
            httpClient.getConnectionManager().closeExpiredConnections();
        }
    }
}
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