[
https://issues.apache.org/jira/browse/HTTPCLIENT-1174?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13230771#comment-13230771
]
jason zhang commented on HTTPCLIENT-1174:
-----------------------------------------
Hi, Oleg, another issue need to mention is when I use fiddle2 to inspect the
session, It shows that response head content length is 6400. If this result is
correct, does it mean the getContentLength() of HttpEntity is not reliable,
while we use this for output content from response?
thank you for your time.
Regards!
> when using HttpResponse's API getEntity return HttpEntity instance to get
> content length, HttpEntity's function API getContentLength() CAN NOT return
> correct content length.
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: HTTPCLIENT-1174
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1174
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Components: HttpClient
> Affects Versions: 4.1.3
> Environment: window xp sp3,java 7.0, Eclipse Java EE IDE for Web
> Developers.Version: Indigo Service Release 1,Build id: 20110916-0149
> Reporter: jason zhang
>
> when using HttpClient get xml data from google API, the response's content
> length is 6400, but HttpEntity's function getContentLength() is -1. sample
> test is bellow.
> ============
> import java.io.InputStream;
> import org.apache.http.HttpEntity;
> import org.apache.http.HttpResponse;
> import org.apache.http.client.HttpClient;
> import org.apache.http.client.methods.HttpGet;
> import org.apache.http.impl.client.DefaultHttpClient;
> import org.apache.http.util.EntityUtils;
> public class testGetContentLength {
> /**
> * @param args
> */
> public static void main(String[] args) {
> HttpClient httpclient = new DefaultHttpClient();
> HttpGet httpget = new
> HttpGet("http://maps.googleapis.com/maps/api/directions/xml?origin=Boston,MA&destination=Concord,MA&waypoints=Charlestown,MA%7CLexington,MA&sensor=false");
> try{
> HttpResponse response = httpclient.execute(httpget);
> HttpEntity entity = response.getEntity();
> if (entity != null) {
> long len = entity.getContentLength();
> System.out.println("length:="+len);
> if (len != -1) {
> System.out.println(EntityUtils.toString(entity));
> } else {
> // Stream content out
> InputStream instream = entity.getContent();
> int l;
> byte[] tmp = new byte[512];
> while ((l = instream.read(tmp)) != -1) {
> System.out.println(new String(tmp,0,l));
>
> }
> //
> // BufferedInputStream in = new
> BufferedInputStream(instream);
> // StringBuffer buffer = new StringBuffer();
> // while((l=in.read(tmp))!=-1){
> // buffer.append(new String(tmp,0,l));
> // }
> // System.out.println(buffer.toString());
> }
> }
> }catch(Exception e){
> e.printStackTrace();
> }
> }
> }
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]