Java Apache HttpClient是否获取添加字节范围标头?

Java Apache HttpClient是否获取添加字节范围标头?,java,android,apache,Java,Android,Apache,有人知道如何在HTTP请求的同时请求字节范围吗?我希望通过请求下载停止位置的字节范围并从getContent()读取其InputStream,来帮助恢复应用程序中的下载 我试着对标题进行迭代,但它们是空的。资料来源如下 import java.io.IOException; import java.io.InputStream; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache

有人知道如何在HTTP请求的同时请求字节范围吗?我希望通过请求下载停止位置的字节范围并从getContent()读取其InputStream,来帮助恢复应用程序中的下载

我试着对标题进行迭代,但它们是空的。资料来源如下

import java.io.IOException;
import java.io.InputStream;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.util.Log;

/**
 * @author Kevin Kowalewski
 *
 */
public class DownloadClient {
DefaultHttpClient httpClient;
HttpGet httpGet;
HttpResponse httpResponse;
HttpEntity httpEntity;
InputStream httpInputStream;

private static String LOG_TAG = DownloadClient.class.getName();

public DownloadClient(){
    httpClient = new DefaultHttpClient();
    httpGet = new HttpGet("http://cachefly.cachefly.net/100mb.test");
    for (Header header : httpGet.getAllHeaders()){
        Log.d(LOG_TAG, "--> Header: " + header);
    }

    Log.d(LOG_TAG, "--> Header size is: " + httpGet.getAllHeaders().length);
    try {
        httpResponse = httpClient.execute(httpGet);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    httpEntity = httpResponse.getEntity();
    try {
        httpInputStream = httpEntity.getContent();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    Log.d(LOG_TAG, "--> StatusLine: " + httpResponse.getStatusLine());
}

public void read(){
    byte[] readBuffer = new byte[32];
    try {
        while (httpInputStream.read(readBuffer) != -1){
            try{Thread.sleep(100);}catch(Exception e){}
            //Log.d(LOG_TAG,"--> Read Bytes: " + new String(readBuffer));
        };
    } catch (IOException e) {
        e.printStackTrace();
    }

}

public void shutdown(){
    httpGet.abort();
    httpClient.getConnectionManager().shutdown();
}
}


Kevin

我通过添加以下行来实现这一点:

httpGet.addHeader("Range", "bytes=0-0");