我有一个Android问题:
我必须能够从生成它们的 URL 中读取内容,然后将它们放入数组中拆分读取的字符串。我使用了不同的方法,但我无法读取该字符串。我能怎么做?
这是我现在使用的函数(继续出现字符串“nn va”):
private void vaia () { // funzione vaia *******************************************************
try {
HttpClient httpclient = new DefaultHttpClient(); // Create HTTP Client
HttpGet httpget = new HttpGet(URL); // Set the action you want to do
HttpResponse response = httpclient.execute(httpget); // Executeit
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent(); // Create an InputStream with the response
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) // Read line by line
sb.append(line + "\n");
String resString = sb.toString(); // Result is here
Log.i("string letta", resString);
is.close(); // Close the stream
}
catch (Exception e) {
Log.i("Risultato eccezione","nn va");
//e.printStackTrace();
}
}
至此的 URL:http: //www.innovacem.com/public/glace/leggiFoto.php(应该写“vuoto”)
谢谢 :)