我试图编写一个程序,它以分块格式从Web服务器获取文件。我想在HTTP 3.0 API中使用ChunkedInputStream类。当我运行代码时,它给了我“意外终止的输入流”错误。我究竟做错了什么?这里是我的代码:分块输入流意外结束
HttpClient client = new DefaultHttpClient();
HttpGet getRequest = new HttpGet(location);
HttpResponse response = client.execute(getRequest);
InputStream in = response.getEntity().getContent();
ChunkedInputStream cis = new ChunkedInputStream(in);
FileOutputStream fos = new FileOutputStream(new ile("session_"+sessionID));
while(cis.read() != -1)
{
fos.write(cis.read());
}
in.close();
cis.close();
fos.close();
我有可能是一个类似的问题,并没有完全下载提取的网页。我想知道PHP CURL库可能比这更好吗? http://www.php.net/manual/en/intro.curl.php – NoBugs