我試圖從NativeScript(android/ios)開發的應用程序調用Sharepoint 2013 REST API。從NativeScript應用程序(android/ios)到Sharepoint 2013 REST API的身份驗證
使用xhr或獲取NativeScript模塊我無法正確認證並調用其餘api。
使用Java我能夠連接到SharePoint服務器並且沒有問題地調用Rest API使用這個maven依賴項:org.apache.httpcomponents httpclient 4.4.1。
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();
}
}
}
任何人都知道與NativeScript相當的Java代碼或獲得Windows身份驗證(NTLM)的方式。
在此先感謝。
你可以看看這個插件npmjs.com/package/nativescript-okhttp。爲了獲得更好的可見性,您可以在[{N} GitHub存儲庫](https://github.com/NativeScript/NativeScript/issues?q=is%3Aissue+is%3Aopen+sort%3Acreated-desc)中打開有關實施的問題這個功能在http模塊中。 –
謝謝,我會嘗試一下Hristo Deshev的例子。 –