在尝试从java Web应用程序访问SharePoint请求的SharePoint Rest API时获取未经授权的异常。根据MSDN,Formdigest对于Post请求是必需的。我们如何从非Microsoft应用程序中使用SharePoint Rest API?
答案 0 :(得分:0)
我建议您阅读此帖Post to SharePoint 2013 from Java。对于您的凭据,我个人使用NTLM(Windows)身份验证,如下所示:
Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
.register(AuthSchemes.NTLM, new JCIFSNTLMSchemeFactory())
.register(AuthSchemes.BASIC, new BasicSchemeFactory())
.register(AuthSchemes.DIGEST, new DigestSchemeFactory())
.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory())
.register(AuthSchemes.KERBEROS, new KerberosSchemeFactory())
.build();
CloseableHttpClient httpClient = HttpClients.custom()
.setDefaultAuthSchemeRegistry(authSchemeRegistry)
.build();
NTCredentials creds = new NTCredentials(user, password, workstation, domain);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, creds);
HttpClientContext context = HttpClientContext.create();
context.setCredentialsProvider(credsProvider);
答案 1 :(得分:0)
您可以尝试我通过共享点Rest api包装常用操作的这个项目