I'm trying to download a file from a Sharepoint repository (where I have regularly access from my corporate network) and I'm doing it from JAVA 7 program.
I'm using the following code, just got from stackoverflow, but my download attempt is failing with error : HTTP/1.1 403 Forbidden
For sake of completeness, the same request is also failing if a try from POSTMAN then it looks due something related to authentication schema. Of course I have no problem when accessing from common WEB browsers.
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(AuthScope.ANY),
new NTCredentials("username", "password", "usernamestring", "passwordstring"));
CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCredentialsProvider(credsProvider)
.build();
try {
HttpGet httpget = new HttpGet("https://xxx.sharepoint.com/sites /YYYYY/default.aspx");
System.out.println("Executing request " + httpget.getRequestLine());
CloseableHttpResponse response = httpclient.execute(httpget);
try {
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
EntityUtils.consume(response.getEntity());
} finally {
response.close();
}
} finally {
httpclient.close();
}