In order to send a string data to the server once, I do as below:
Make “HttpURLConnection” to my URL address and open it
Set the required headers
for the connection I Set setDoOutput to True
new a DataOutputStream from my connection and finally write my string data to it.
HttpURLConnection myConn = (HttpURLConnection); myUrl.openConnection(); myConn.setRequestProperty("Accept", "application/json, text/plain, */*"); myConn.setDoOutput(true); DataOutputStream my_output = new DataOutputStream(myConn.getOutputStream()); my_output.write(myData.getBytes("UTF-8"));
But what to do if I want to send exactly the same data with same URl and headers multiple times? Can I write to it multiple times?(I mean that is it possible to use the last line of code multiple times?) Or should I repeat the above steps and try it with a new connection? And if yes should I wait for some second or millisecond before sending the next one? I also searched for some other alternatives such as “HttpClient” Http API and making synchronous Http request which as far as I got can help me setting the headers only once. At the end, I appreciate your help and support and any other alternatives would be welcome. Thanks a million.