We are trying to connect to Sharepoint 2013 using rest based api using a java program. Our code is -
DefaultHttpClient httpclient = new DefaultHttpClient();
List<String> authpref = new ArrayList<String>();
authpref.add(AuthPolicy.NTLM);
// httpclient.getParams().setParameter(AuthPNames.CREDENTIAL_CHARSET,
// authpref);
NTCredentials creds = new NTCredentials(userName, password, "portal", "xyz.com");
httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);
HttpHost target = new HttpHost("portal.xyz.com", 80);
// Make sure the same context is used to execute logically related
// requests
HttpContext localContext = new BasicHttpContext();
// Execute a cheap method first. This will trigger NTLM authentication
HttpGet httpget = new HttpGet("http://portal.xyz.com/Sites/XYZteam/_api/web/GetFolderByServerRelativeUrl('/Sites/XYZteam/GlobalBrandBook')/Files");
httpget.addHeader("Accept", "application/json;odata=verbose");
httpget.addHeader("X-HTTP-Method", "GET");
httpget.addHeader(HttpHeaders.USER_AGENT, "Mozilla/4.0+(compatible;+MSIE+5.01;+Windows+NT+5.0");
HttpResponse response = httpclient.execute(target, httpget, localContext);
HttpEntity entity = response.getEntity();
System.out.println(EntityUtils.toString(entity));
We also tried basic authentication/ Invoking SOAP Based Services but every time we keep getting 403 Forbidden error. Any clues will be of great help. Tina