After HTTP GET request, the resulting string is cut-off - content has been consumed

对着背影说爱祢 提交于 2019-11-29 11:07:58

OK I solved it.
As I understand, the content of the entity gets consumed if it's not "used". So I created a new String object with the content of the Entity, so to say a copy instead of a reference to the entity's content.

try {
    HttpClient client = new DefaultHttpClient();  
    String getURL = "http://busspur02.aseag.de/bs.exe?SID=5FC39&ScreenX=1440&ScreenY=900&CMD=CR&DatumT="+day+"&DatumM="+month+"&DatumJ="+year+"&ZeitH="+hour+"&ZeitM="+min+"&Intervall=120&Suchen=(S)uchen&GT0=Aachen&T0=H&HT0="+start_from+"&GT1=Aachen&T0=H&HT1="+destination+"";
    HttpGet get = new HttpGet(getURL);
    HttpResponse responseGet = client.execute(get);  
    HttpEntity resEntityGet = responseGet.getEntity();  
    String sourceString = "";

    if (resEntityGet != null) {                 
        try {
            dismissDialog();
            sourceString= new String(EntityUtils.toString(resEntityGet));
            Log.i("GET RESPONSE", sourceString);
        } catch (ParseException exc) {
            // TODO Auto-generated catch block
            exc.printStackTrace();
        } catch (IllegalStateException exc) {
            // TODO Auto-generated catch block
            exc.printStackTrace();
        }
        ...
    }
    ...
} catch(...) {
...
}

DixieFlatline is correct.

With this I get partial output:

Log.v(TAG, "RESPONSE: " + response);

With this I get full output:

for(String line : response.split("\n"))
   Log.v(TAG, "LINE: " + line);

I think that Log limits the number of chars to 4070. I tried to display a long string in ddms locgat and i got only 4070 chars.

Great!

By the way, if you are using Eclipse with Debug perspective, at the "Variables" view:

(Window -> Show View -> Variables)

you can right-click on the window, select "Max Length" and insert "0".

This way you can see all the chars (the complete html) in the Variables view.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!