简体   繁体   中英

Android: If I get HttpResponse status code 200, then there's no data lost?

I have a question about Android(Java) HttpRequest and HttpResponse. I use Apache library.

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

HttpGet httpGet = new HttpGet(uri);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(httpGet);

if(response.getStatusLine().getStatusCode() == 200) {
    BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    StringBuilder sb = new StringBuilder();
    String str = "";
    while ((str = br.readLine()) != null) {
        sb.append(str);
    }
}

And the response content response.getEntity().getContent() size is about 500KB

Can I say that if I get status code 200 and I can read the content until EOF (End Of File) then there's no data lost via network transportation?

Or I cannot make sure if there is data lost so I need a CheckSum mechanism to check?

Thanks. Eric

Well ... that should be the case, right? :) If you have read all the entity content without exception, you've got the complete, correct response body. No need to add your own checksum.

The only problem I can see, is HTTP/1.0 server or intermediaries. If they use TCP FIN to end a response, the response body might be terminated prematurely without client's knowledge.

I don't think we need to worry about HTTP/1.0 at this point of time. If you do, you can design your data format so that premature termination can be detected on the client side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM