public static SimpleEntry<Integer, String> doPost(URI uri, Map<String, String> headers, String body) throws IOException { HttpURLConnection conn = getConnection(uri); conn.setRequestMethod("POST"); if (headers != null) { for (Entry<String, String> header : headers.entrySet()) { conn.setRequestProperty(header.getKey(), header.getValue()); } } System.out.println(">>>> Sending 'POST' request to URL : " + uri); conn.setDoOutput(true); writeStream(conn.getOutputStream(), body); int responseCode = conn.getResponseCode(); String responseBody = conn.getHeaderField(Operation.REQUEST_AUTH_TOKEN_HEADER); System.out.println("Response Code : " + responseCode); System.out.println("Response Body : " + responseBody); return new SimpleEntry<>(responseCode, responseBody); }
public static SimpleEntry<Integer, String> doDelete(URI uri, Map<String, String> headers) throws IOException { HttpURLConnection conn = getConnection(uri); conn.setRequestMethod("DELETE"); if (headers != null) { for (Entry<String, String> header : headers.entrySet()) { conn.setRequestProperty(header.getKey(), header.getValue()); } } System.out.println(">>>> Sending 'DELETE' request to URL : " + uri); int responseCode = conn.getResponseCode(); String responseBody; try { responseBody = readStream(conn.getInputStream()); } catch (IOException e) { responseBody = readStream(conn.getErrorStream()); } System.out.println("Response Code : " + responseCode); System.out.println("Response Body : " + responseBody); return new SimpleEntry<>(responseCode, responseBody); }
public static SimpleEntry<Integer, String> doGet(URI uri, Map<String, String> headers) throws IOException { HttpURLConnection conn = getConnection(uri); conn.setRequestMethod("GET"); if (headers != null) { for (Entry<String, String> header : headers.entrySet()) { conn.setRequestProperty(header.getKey(), header.getValue()); } } System.out.println(">>>> Sending 'GET' request to URL : " + uri); int responseCode = conn.getResponseCode(); String responseBody; try { responseBody = readStream(conn.getInputStream()); } catch (IOException e) { responseBody = readStream(conn.getErrorStream()); } System.out.println("Response Code : " + responseCode); System.out.println("Response Body : " + responseBody); return new SimpleEntry<>(responseCode, responseBody); }