나는 아주 이상한 문제에 부딪 쳤고, 나는 어디에서 시작해야하는지 조금이라도 생각하지 못했다.HTTP 응답이 중단 된 문자열은 무엇입니까? - 자바, 플랫폼 안드로이드 3.0
서버에 http 요청을 보내고 응답으로 간단한 문자열을 가져옵니다. 이것은 내 스마트 폰 응용 프로그램에서 정상적으로 작동했습니다. 그것은 심지어 내 브라우저에서 잘 작동합니다. 그러나 스마트 폰 코드를 복사하여 붙여 넣기 만한다고 생각하는 동안 앱의 내 태블릿 (Android 3.0.1) 버전에서는 더 이상 작동하지 않습니다.
나는 디버거를 검사했고 이전 버전은 길이가 2958자인 문자열을 얻습니다. 새로운 버전은 길이가 1334 인 문자열 만 가져옵니다. 새 버전의 URL을 기록한 다음 브라우저에 넣고 2985 자의 문자열을 다시 가져 왔습니다.
내 코드에서 큰 차이점을 찾을 수 없습니다 (아래 참조). 또한, 나는 안드로이드에서 문자열 길이를 제한하는 몇 가지 변화가 있었다고 믿을 수 없습니까?!
아무도 아이디어가 있습니까?
기존 스마트 폰 코드 : 새로운 태블릿 버전
if (CheckInternet())
{
myURL = new URL(params[0]);
httpClient = AndroidHttpClient.newInstance("android");
if (rtype == RequestType.GET)
{
httpRequest = new HttpGet(myURL.toExternalForm());
}
else
{
httpRequest = new HttpPost(myURL.toExternalForm());
HttpEntity myEntity = new StringEntity(message, "UTF-8");
((HttpPost) httpRequest).setEntity(myEntity);
}
HttpParams httpParams = new BasicHttpParams();
HttpProtocolParams.setHttpElementCharset(httpParams, "UTF-8");
HttpProtocolParams.setContentCharset(httpParams, "UTF-8");
HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
HttpConnectionParams.setSoTimeout(httpParams, timeout);
httpRequest.setParams(httpParams);
response = httpClient.execute(httpRequest);
final int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == 300 || statusCode >= 305)
{
errorMessage = getStatusCodeMessage(statusCode, act);
}
else
{
HttpEntity entity = response.getEntity();
if (entity != null)
{
InputStream instream = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(instream, "UTF-8"));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
sb.append(line);
result = sb.toString();
}
}
}
코드 :
if (CheckInternet())
{
if (isCancelled()) return null; //that's for an AsyncTask
URL myURL = new URL(params[0]);
httpClient = AndroidHttpClient.newInstance("android");
if (isCancelled()) return null;
if (params[1] == null)
{
httpRequest = new HttpGet(myURL.toExternalForm());
}
else
{
httpRequest = new HttpPost(myURL.toExternalForm());
HttpEntity myEntity = new StringEntity(params[1], "UTF-8");
((HttpPost) httpRequest).setEntity(myEntity);
}
httpRequest.setParams(httpParams);
if (isCancelled()) return null;
HttpResponse response = httpClient.execute(httpRequest);
httpClient.close();
if (isCancelled()) return null;
final int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == 300 || statusCode >= 305)
{
error = HttpHelper.getStatusCodeMessage(statusCode, getActivity());
}
else
{
if (isCancelled()) return null;
HttpEntity entity = response.getEntity();
if (entity != null)
{
InputStream instream = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(instream, "UTF-8"));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
sb.append(line);
String test = sb.toString(); //that was for debugging the string
return test;
}
}
}
이 두 요청은 AsyncTask를 실행하고 있습니다.
종류의 안부 해파리
는 로그'를 통해 로그 아웃 문자열을 쓰고있다. >()'? 로그에는 최대 출력 길이가 있으므로 문자열을 500 자 이하의 문자로 나눠서 모든 것이 인쇄되도록하는 것이 가장 좋습니다. – LeffelMania
[EntityUtils] (http://developer.android.Entity를 문자열로 검색 할 때 유용하여 마지막 10 줄 정도를 필요로하지 않게 해줍니다. –
@LeffelMania : 아니요, 디버깅 옵션으로 중단하고 문자열 길이를 확인했습니다. @ 데이비드 Caunt : 감사합니다! – jellyfish