Sharepoint java sdk,从JAVA到Sharepoint 2013 REST API的BASIC身份验证

Would prefer to use BASIC authentication:

There are many examples of using the rest api's on the web but none seem to deal with authentication. Maybe I'm missing something really simple here.

This works manually via POSTMAN:

http://tech.bool.se/basic-rest-request-sharepoint-using-postman/

but requires me to enter username and password in browser.

I've tried implementing this:

HttpClientBuilder basic auth

using

org.apache.httpcomponents

httpclient

4.4.1

This results in -> WARNING: NTLM authentication error: Credentials cannot be used for NTLM authentication: org.apache.http.auth.UsernamePasswordCredentials

解决方案

Thanks @fateddy that does the trick:

Remember to switch out UsernamePasswordCredentials("username", "password"));for NTCredentials(, , ,);

org.apache.httpcomponents

httpclient

4.4.1

The authentication to SharePoint works:

public class SharePointClientAuthentication {

public static void main(String[] args) throws Exception {

CredentialsProvider credsProvider = new BasicCredentialsProvider();

credsProvider.setCredentials(

new AuthScope(AuthScope.ANY),

new NTCredentials("username", "password", "https://hostname", "domain"));

CloseableHttpClient httpclient = HttpClients.custom()

.setDefaultCredentialsProvider(credsProvider)

.build();

try {

HttpGet httpget = new HttpGet("http://hostname/_api/web/lists");

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();

}

}

}

And you end up with :

HTTP/1.1 200 OK

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值