I have a problem when I run my code, after opening HTTP request i'm trying to retrieve the response code, but then the program stop running on print statement Below is my code:
private static HttpURLConnection openHttpConnection(URL url, String method){
try {
HttpURLConnection connection = null;
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod(method);
connection.setRequestProperty("Content-Type",
"application/json;charset=UTF-8");
connection.setRequestProperty("Accept", "application/json");
System.out.println(connection.getResponseCode());
}
catch (Exception exception) {
exception.printStackTrace();
}
the program stopped in last line, the problem appear when I open many HTTP requests after each other. Note: when I debug the same code it works with dubbing but not with running. Also the problem appear after 8 HTTP requests.
Please help. Thank you.