Thread thread = new Thread(new Runnable() { u/Override public void run() { try { try { String clientId = "af52e5b3d******c2d81bade***6c055"; //Replace with your client ID String clientSecret = "e868414f******183267d398d578a448c6a1a70bf8be2896ebc******b013bc"; //Replace with your client Secret String script = editText.getText().toString(); String language = "java"; String versionIndex = "0"; URL url = new URL("https://api.jdoodle.com/v1/execute"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json"); String input = "{\"clientId\": \"" + clientId + "\",\"clientSecret\":\"" + clientSecret + "\",\"script\":\"" + script + "\",\"language\":\"" + language + "\",\"versionIndex\":\"" + versionIndex + "\"} "; System.out.println(input); OutputStream outputStream = connection.getOutputStream(); outputStream.write(input.getBytes()); outputStream.flush(); if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { throw new RuntimeException("Please check your inputs : HTTP error code : " + connection.getResponseCode()); } BufferedReader bufferedReader; bufferedReader = new BufferedReader(new InputStreamReader( (connection.getInputStream()))); StringBuilder results = new StringBuilder(); String output1; System.out.println("Output from JDoodle .... \n"); while ((output1 = bufferedReader.readLine()) != null) { results.append(output1); } connection.disconnect(); output.setText(results); } catch (IOException e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } } }); thread.start();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)