1

We have this code which we are using to post data from an Android app to a .Net Rest service. One of the fields that the backend is and array. Swagger specifies it as

modelbinding Array[integer]

How should we put the value array of integers in the urlParameters so we can post it?

String urlParameters = "field1=abc&field2=def";

URL url = new URL(targetURL);

connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", contentType);
connection.setRequestProperty("Accept-Charset", "UTF-8");
connection.setUseCaches (false);
connection.setDoInput(true);
connection.setDoOutput(true);

// Send request
writer = new DataOutputStream (connection.getOutputStream ());
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(writer, "UTF-8"));
bufferedWriter.write(urlParameters);
bufferedWriter.flush ();
bufferedWriter.close (); 

1 Answer 1

1

Using Json format is the best way to send data. you can convert your data in json array then json array to string. Now your string(represented in json formate) can easily be sent.

Sign up to request clarification or add additional context in comments.

3 Comments

We've tried sending json but we have some issues there also. Like the above it's working except for one array typed field in the backend. Do you have any solution if we want to send the data like this?
@MathiasR, can you please tell me what type of issue you have encountered in sending json data?
Ended up converting all payloads to json

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.