1

In android when I make a http post, I create the url parameters using this code:

I want to send a string and two string lists in the http request. However in the php code, I can't verify if all parameters are there. In the below code, I expect the php if statement to be true, but its being false. Does anyone know whats wrong here?

I saw from the answer here how to loop through a set of GET values in php that you could put the name of a parameter with square brackets and then in php it would be an array.

Thanks.

    List<NameValuePair> urlValues = new ArrayList<NameValuePair>();

    urlValues.add(new BasicNameValuePair("id", ID));

    for(MyLocation item : THlocationList) {
       urlValues.add(new BasicNameValuePair("THlocationList[]", item.ID));
       urlValues.add(new BasicNameValuePair("THlocationList[]", item.location));
       urlValues.add(new BasicNameValuePair("THlocationList[]", item.date));
    }
    for(String item : deletionList ) {
       urlValues.add(new BasicNameValuePair("deletionList[]", item));
    }

Then I make the request using this:

public static Pair<String,Integer> GetHTTPResponse(String url, List<NameValuePair> urlparameters) {
    String result = null;
    int responseCode = 0;

    try {
        HttpClient client = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(url);

        httppost.setEntity(new UrlEncodedFormEntity(urlparameters));
        HttpResponse response = client.execute(httppost);
        responseCode = response.getStatusLine().getStatusCode();    

        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        result = rd.readLine().trim();
    }
    catch (Exception e) {
        responseCode = 0;
    }

    return new Pair<String, Integer>(result, responseCode);
}

In my php code, for some reason this is evaluating to false:

if (isset($_POST['id']) && isset($_POST['THlocationList']) && isset($_POST['deletionList'])) {
    ...
}
Community
  • 1
  • 1
sneaky
  • 2,141
  • 9
  • 31
  • 38
  • What do you get as a response in your Android ? – mt0s Jul 29 '13 at 01:47
  • Well, in the php code, I set it so if the if statement is false, I print some string, and that is the exact string I am getting, so I know that if statement is becoming false. – sneaky Jul 29 '13 at 01:54

0 Answers0