HttpResponse returns null

Thursday, July 3, 2014

I want to search a diretory with the following php script and get the displayed JSONArray via android app. But everytime I call the android app the HttpResponse null and i dont know why.


$pfad = "./months";
$files = scandir($pfad);
$result = array();
for($a = 2; $a < count($files); $a++)
$result[] = $files[$a];
print json_encode($result);

If I open the script on my server i get ["5.txt","June2014.txt"].


import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {

JSONArray finalResult;
Integer responseCode;
TextView show;

protected void onCreate(Bundle savedInstanceState) {

new MyAsyncTask().execute();

show = (TextView)findViewById(;


public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(, menu);
return true;

private class MyAsyncTask extends AsyncTask<String, Integer, Integer>{

protected Integer doInBackground(String... params) {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("myurl.php");

try {
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
int responseCode = response.getStatusLine().getStatusCode();

} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
return null;




Note: myurl.php is really the the right server address.

I'd be happy for any help