从NativeScript应用程序(android/ios)到Sharepoint 2013 REST API的身份验证

从NativeScript应用程序(android/ios)到Sharepoint 2013 REST API的身份验证,rest,mobile,sharepoint-2013,nativescript,Rest,Mobile,Sharepoint 2013,Nativescript,我试图从使用NativeScript(android/ios)开发的应用程序调用Sharepoint 2013 REST API 使用xhr或fetch NativeScript模块,我无法正确地进行身份验证并调用rest api 使用Java,我能够连接到sharepoint服务器并调用RESTAPI,而使用这个maven依赖项没有问题:org.apache.httpcomponents-httpclient 4.4.1 public class SharePointClientAuthent

我试图从使用NativeScript(android/ios)开发的应用程序调用Sharepoint 2013 REST API

使用xhr或fetch NativeScript模块,我无法正确地进行身份验证并调用rest api

使用Java,我能够连接到sharepoint服务器并调用RESTAPI,而使用这个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)工作的方法


提前感谢。

起初我认为这应该由本机HTTP库处理,并作为NativeScript中XMLHttpRequest实现的一部分公开,但后来我发现。这是一个小型库,为您处理NTLM挑战响应

我对它进行了一些修补,以摆脱浏览器依赖性,并推出了一些polyfill,然后让它运行起来。我在这里展示了一个演示项目:


您可以查看这个插件npmjs.com/package/nativescript-okhttp。为了获得更好的可视性,您可以在中打开一个关于在http模块中实现此功能的问题。谢谢,我将尝试Hristo Deshev的示例。感谢此演示,我将尝试使用rest sharepoint api!我正在考虑编写一个nativescript包来处理Sharepoint Rest操作,其中包含三种身份验证类型ntlm、basic和online。