I have server that takes list of int or one int. When I send int, it works good, but when Im trying send List<Integer>
or int[]
, response is error(code 400
) always. How I can send list of int? Here is my code:
url = new URL(adress);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
urlConnection.setRequestMethod("POST");
urlConnection.setUseCaches(false);
urlConnection.setConnectTimeout(10000);
urlConnection.setReadTimeout(10000);
urlConnection.setRequestProperty("Content-Type","application/json");
"android.schoolportal.gr");
urlConnection.connect();
JSONObject jsonParam = new JSONObject();
jsonParam.put("categories_okpd_2", list);
OutputStreamWriter out = new OutputStreamWriter(urlConnection.getOutputStream());
out.write(jsonParam.toString());
out.close();
I tried list
like a:
int myInt = 1;
List<Integer> list = new ArrayList<Integer>();
list.add(myInt);
and
int[] list = new int[5];
but it always results in an error with code:400
.