This is only an exercise. I'm wondering if there is an equivalent of this code:
String https_url = "https://api.ciscospark.com/v1/rooms";
URL url = new URL(https_url);
HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
connection.setRequestProperty("Authorization", "I3MDUtMmEy");
connection.setDoOutput(true);
I thought that could be possible to make something like:
String https_url = "https://api.ciscospark.com/v1/rooms";
URL url = new URL(https_url);
HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();
connection.setDoOutput(true);
PrintWriter pw = new PrintWriter(connection.getOutputStream());
pw.println("GET /v1/rooms HTTP/1.1");
pw.println("Host: https://api.ciscospark.com");
pw.println("Content-Type: application/json; charset=utf-8");
pw.println("Authorization: I3MDUtMmEy");
pw.println("");
but I receive auth error message from Server returned HTTP response code: 401 for URL: https://api.ciscospark.com/v1/rooms 401 Authentication credentials were missing or incorrect. Can I use printwriter to make it work? And if not, why? thanks