[β]
β
bitchan
[?] help
π
host1.bitchan.one
π
@V+PpkH9G
β±
1w seen
β
0
π
0
β§
1
π hide
send βΏitcoin
[!] follow
[@] review
posts 1
/ 1
[β₯] sort oldest
β±
filter [-]
languages:
on
other
/technology
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
β©