π“Ÿ host1.bitchan.one

𓀐 @V+PpkH9G

⏱ 1w seenβ›“ 0πŸ‘ 0β§– 1

filter [-]

languages:onother

And yet here's what some old school Java looks like, which is part of why so many of us flocked to dynamically typed languages final String jsonPayload = "{\n" + " \"name\": \"Jane Doe\",\n" + " \"email\": \"jane.doe@example.com\"\n" + "}\n"; final ExecutorService executor = Executors.newFixedThreadPool(1); Future<String> futureResponse = executor.submit(new Callable<String>() { @Override public String call() throws Exception { HttpURLConnection connection = null; try { URL url = new URL("https://example.com"); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json"); connection.setDoOutput(true); try (DataOutputStream wr = new DataOutputStream(connection.getOutputStream())) { wr.writeBytes(jsonPayload); wr.flush(); } int responseCode = connection.getResponseCode(); StringBuilder response = new StringBuilder(); try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { String inputLine; while ((inputLine = in.readLine()) != null) { response.append(inputLine); } } return response.toString(); } finally { if (connection != null) { connection.disconnect(); } } } }); try { String response = futureResponse.get(); formatResponse(response); } catch (Exception e) { e.printStackTrace(); } finally { executor.shutdown(); }⏱ 1w↩