임 BufferedReader의 불완전 응답, 간단한 HTTP 얻을 내 결과에 내가 볼안드로이드 무엇 임 잘못
불완전한 응답, 일을하고 HttpGet?
class GetDocuments extends AsyncTask<URL, Void, Void> {
@Override
protected Void doInBackground(URL... urls) {
Log.d("mensa", "bajando");
//place proper url
connect(urls);
return null;
}
public static void connect(URL[] urls)
{
HttpClient httpclient = new DefaultHttpClient();
// Prepare a request object
HttpGet httpget = new HttpGet("http://tiks.document.dev.chocolatecoded.com.au/documents/api/get?type=tree");
// Execute the request
HttpResponse response;
try {
response = httpclient.execute(httpget);
// Examine the response status
Log.d("mensa",response.getStatusLine().toString());
// Get hold of the response entity
HttpEntity entity = response.getEntity();
// If the response does not enclose an entity, there is no need
// to worry about connection release
if (entity != null) {
// A Simple JSON Response Read
InputStream instream = entity.getContent();
String result= convertStreamToString(instream);
// now you have the string representation of the HTML request
Log.d("mensa", "estratagema :: "+result);
JSONObject jObject = new JSONObject(result);
Log.d("mensa", "resposta jObject::"+jObject);
Log.d("mensa", "alive 1");
JSONArray contacts = null;
contacts = jObject.getJSONArray("success");
Log.d("mensa", "resposta jObject::"+contacts);
Log.d("mensa", "alive");
//instream.close();
}
} catch (Exception e) {}
}
private static String convertStreamToString(InputStream is) {
/*
* To convert the InputStream to String we use the BufferedReader.readLine()
* method. We iterate until the BufferedReader return null which means
* there's no more data to read. Each line will appended to a StringBuilder
* and returned as String.
*/
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
Log.d("mensa", "linea ::"+line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
}
내가 그것을 전화 : 내가 잘립니다 응답으로 불완전한를 참조
GetDocuments get = new GetDocuments();
URL url = null;
try {
url = new URL("ftp://mirror.csclub.uwaterloo.ca/index.html");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//URL url = new URL("http://www.google.es");
get.execute(url);
편집 한 여기에 코드
? 문자열이 잘립니다 방법
이 때문에 로그 크기? 하지만 다른 문제이며, 응답의 이미지 아래는 구문 분석하지 않는다는 것입니다에주의하시기 바랍니다?
감사합니다!
INCOMPLETE 응답으로 더 자세히 지정할 수 있습니까? 나는 당신의 코드를 디버깅하려하고 JSONException이 던져진다. 09-23 14 : 04 : 42.045 : E/a (507) : org.json.JSONException : java.lang.Boolean 유형의 성공시 값이 JSONArray로 변환 될 수 없음 – edisonthk
예외가 발생하지 않으며 다음으로 수정을 참조하십시오. 응답, tnx에 대한 잘린 문자열을 확인하십시오. – MaKo
오, 나중에 코드를 편집하기 때문에 예외가 발생합니다. 귀하의 GetDocuments 클래스 연결 메서드에서 귀하의 예외에 로그를 추가하면 그것을 볼 수 – edisonthk