Premature end of Content-Length delimited message body (expected:

前端 未结 2 2544
粉色の甜心
粉色の甜心 2020-12-06 10:23

I am trying to get HTTP response with the help of apache httpclient. I get headers successfully but it throws exception when I try to get contents. Exception is:

<         


        
相关标签:
2条回答
  • 2020-12-06 10:29

    The problem appears to be on the server-side, not in the client code you've pasted.

    The server claimed that the content contained 203856 bytes but only sent 1070.

    0 讨论(0)
  • 2020-12-06 10:46

    I might be replying on it late. But I also encounter the same problem. And I got the resolution of it. In my case I was closing the client before utilizing the HttpEntity. And after closing the client I was trying to download the file. Below code is similar to what I was doing:

    HttpEntity httpEntity = null;
    try (final CloseableHttpClient client = createHttpClient()) {
         httpEntity = getEntity(client);
    }
    
    return downloadFile(httpEntity, targetDirectory, fileName);
    

    After adjusting my code to download the file before closing the client, Its working now for me. Below code is similar to what I did now:

    try (final CloseableHttpClient client = createHttpClient()) {
         HttpEntity httpEntity = getEntity(client);
         return downloadFile(httpEntity, targetDirectory, fileName);
    }
    
    0 讨论(0)
提交回复
热议问题