I have a question related to Http. In android how to list the files of a folder which is in Http server.
I am able to Download file from server. But I want to check fil
Server script to get a list of files as a string separated by "-" :
Android code to get string from server and separate the filenames:
try {
int timeout= 7000;
HttpPost httppost= null;
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, timeout);
httppost = new HttpPost("http://yourserver/getlist.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}
catch(Exception e) {
e.printStackTrace();
}
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"),8);
sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
String line="0";
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
}
catch(Exception e){
e.printStackTrace();
}
for (String getFile: result.split("-")){
Log.d("abc","String is:" + getFile);
}