title: Multiple HttpURLConnection calls for get throwing Premature end of file exception with InputStream
body: <p>I'm trying to make multiple calls to a REST API using <code>HttpURLConnection</code> with GET method and retrieving the response through InputStream.</p>
  
  <p>It worked fine previously for 3 months but now it's throwing below exception:</p>
  
  <blockquote>
    <blockquote>
      <p>SAXException Occurred during getArtifactsUrl method:: org.xml.sax.SAXParseException; Premature end of file.
              at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) [xercesImpl.jar:6.1.0.Final]
              at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source) [xercesImpl.jar:6.1.0.Final]
              at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121) [:1.7.0_03]</p>
    </blockquote>
  </blockquote>
  
  <p>Below is the line of code where I'm making the second call to parse the response:</p>
  
  <pre><code>request = (HttpURLConnection) endpointUrl.openConnection();             
  inputstream = request.getInputStream();             
  doc = dBuilder.parse(inputstream);
  </code></pre>
  
  <p>First call is working fine using request and inputstream objects but second call is failing. I tried all possible answers I found in google but no luck:
  after every call:</p>
  
  <pre><code>inputstream.close();
  request.disconnect();
  </code></pre>
  
  <p>Remember that request is an HttpURLConnection object.</p>
  
  <p>I greatly appreciate if you can be able to solve this as I this is a high prioirity production issue now!</p>