I have a usecase where I have a set of HTTPS GET requests which are password protected, I want to access the Request body but without passing username/password everytime, instead using the my Chrome browser session.
Here is how I am trying by creating new HTTP connection everytime giving my credentials, which is not suggestible and also slow.
String url = "<Request URL>";
URL obj = new URL(url);
String encoding = Base64.getEncoder().encodeToString(("<username>:<password>").getBytes());
System.out.println("Encoded Credential String:==>"+encoding);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
con.setDoOutput(true);
con.setRequestProperty ("Authorization", "Basic " + encoding);
System.out.println("Response connection string: "+con.toString());
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
//print result
System.out.println(response.toString());
Can someone please provide me directions, how I should proceed if my implementation is in Java ?