So I've been trying for a while to make many calls to an API with POST request, where I need to parse the access token of my devices in the URL, which I've stored them in an array,
String [] arr = new String[49];
arr[0] = "Access_Token1";
arr[1] = "Access_Token2";
What I need to do in to iterate through the array and get every access token, put it in the url to make the request, this is the code I used to make one call to the API, but I had no idea how to do for many post request
String paramValue = "param\\with\\backslash";
String yourURLStr = "http://host.com?param=" + java.net.URLEncoder.encode(paramValue, "UTF-8");
URL url2 = new URL("https://demo.thingsboard.io/api/v1/H2arM3bxFwobsGMAM5Rt/telemetry");
for (int i=0; i<list.size(); i++) {
HttpsURLConnection conn = (HttpsURLConnection) url2.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Authorization", "Bearer");
conn.setDoOutput(true);
OutputStream outStream = conn.getOutputStream();
OutputStreamWriter outStreamWriter = new OutputStreamWriter(outStream, "UTF-8");
outStreamWriter.write(list.get(1).toString());
//outStreamWriter.write(list.toJSONString());
outStreamWriter.flush();
outStreamWriter.close();
outStream.close();
String response = null;
System.out.println(conn.getResponseCode());
System.out.println(conn.getResponseMessage());
DataInputStream input1 = null;
input1 = new DataInputStream (conn.getInputStream());
while (null != ((response = input1.readLine()))) {
System.out.println(response);
input1.close ();
}
}}
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}
can anyone give me a clue how to do so, It's been 3 weeks trying to do that and I'm still stuck in here.