Tôi gặp sự cố khi tôi muốn phân tích cú pháp tệp XML trên web. Bây giờ tôi HttpResponce được quá nhiều thời gian quá đọc rằng tập tin XML, vì vậy tôi nhận được lỗi "Trở thành Runtime Error" cho GUI của tôi.HttpResponse trong Android
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://chukk.nuzoka.com/name.xml");
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
line = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
} catch (MalformedURLException e) {
line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
} catch (IOException e) {
line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
}
Any help is appreciated :)
bạn làm điều này theo chủ đề riêng biệt phải không? – L7ColWinters
Chỉ cần một lưu ý phụ, hãy xem xét sử dụng StreamReader thay vì EntityUtils.toString, để cải thiện mức sử dụng bộ nhớ. – yorkw
@yorkw Bạn có gì để sao lưu điều đó không? Tôi đang sử dụng EntityUtils .. – nhaarman