2
private HttpResponse doResponse(String url) {
HttpClient httpclient = new DefaultHttpClient(getHttpParams());
HttpResponse response = null;
try {
HttpGet httpget = new HttpGet(url);
response = httpclient.execute(httpget);
} catch (Exception e) {
Log.e(TAG, e.getLocalizedMessage(), e);
}
return response;
}
@Override
protected String doInBackground(String... urls) {
// TODO: attempt authentication against a network service.
String url = urls[0];
String result ="";
try {
HttpResponse response=doResponse(url);
result = inputStreamToString(response.getEntity().getContent());
//throws IllegalStateException: Content has been consumed
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
Log.e(TAG, e.getLocalizedMessage(), e);
}
return result;
}
라인IllegalStateException이 : 콘텐츠가 소비되었다 (제 1의 getContent()를)
result = inputStreamToString(response.getEntity().getContent());
는 내가 전에 컨텐츠를하지 않았다하더라도
IllegalStateException: Content has been consumed
가 발생합니다.
나는 내 코드의 마녀 부분은 안드로이드 4.1.1
우리에게 inputStreamToString()'당신의 도움의 도움을 – jnthnjns
@Asok 들으 (나는 이유를 설명 할 수 없다)하지만 예외가 단지 디버그 모드로 여기 '에 대한 코드를 보여주십시오, 아무것도, 실행 모드에 잘못 없다 은 http 요청의 타임 아웃이 될 수있다. – Simo
'getContent()'만 한번 호출했는지 확인하고,'inputStreamToString()'메서드 내에서 호출하지 않도록하라. – jnthnjns