I need to read a Excel Sheet but when I am using URLConnection it is landing me on the login page.
URLConnection uc = url.openConnection();
HttpURLConnection httpConnection = (HttpURLConnection) uc;
String basicAuth = Base64.getEncoder().encodeToString((username+":"+password).getBytes(StandardCharsets.UTF_8));
httpConnection.setRequestProperty("Authorization","Basic " + basicAuth);
httpConnection.setRequestProperty("User-Agent","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36");
httpConnection.connect();
BufferedReader r = new BufferedReader(new InputStreamReader(httpConnection.getInputStream(), Charset.forName("UTF-8")));
StringBuilder sb = new StringBuilder();
String line;
while((line = r.readLine())!= null){
sb.append(line);
sb.append("\n");
}
System.out.println(sb.toString());
I tried setting Authorisation headers but still cannot achieve it. Can someone help me.