0

I'm doing a GET request with version 4.3.3 of Apache HttpClient, like this:

HttpGet httpGet = new HttpGet("http://www.revenue.ie/en/tax/it/forms/med1.pdf");
CloseableHttpClient client = HttpClients.createDefault();
CloseableHttpResponse response = client.execute(httpGet);
client.close();

The response status code tells me 200, and the content length as returned by response.getEntity().getContentLength() is 1213954, but the InputStream as returned from a call to:

response.getEntity().getContent()

...is reporting 0 bytes available.

I have been successfully making GET calls like this to retrieve and parse the HTML of other URLs, but is there something different I need to do here since it's file contents that I'm interested in?

RTF
  • 6,214
  • 12
  • 64
  • 132

1 Answers1

0

The problem was that I was closing the http client too early i.e. client.close() before I tried to retrieve the response InputStream with a call to response.getEntity().getContent().

RTF
  • 6,214
  • 12
  • 64
  • 132