android – Sending an int array using the POST method


Good afternoon. I am using AsyncTask and using the POST method I send a pair of HashMap<String, String> to the server without any problem, but what about the int[] array? How to send an array correctly?


I think Json will help you

List<Integer> productIds = ...
JSONArray x = new JSONArray();
for(Integer productId : productIds){

or if int[]

JSONArray x = new JSONArray();
for(int k=0; k < size; k++){

then we send it to the server. There are many methods, one option

 try {
    HttpClient client = new DefaultHttpClient();  
    String postURL = "";
    HttpPost post = new HttpPost(postURL); 
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("intlist", x.toString()));
        UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params,HTTP.UTF_8);
        HttpResponse responsePOST = client.execute(post);  
        HttpEntity resEntity = responsePOST.getEntity();  
        if (resEntity != null) {    
} catch (Exception e) {

well, on the server, you can then transfer it back to the array

$list = $_POST['intlist'];

$obj = json_decode($list);
Scroll to Top