为SharePoint 2013创建跨平台移动应用程序

5
我希望为我工作的SharePoint服务器制作一个简单的CRUD跨平台移动应用程序。 我正在使用PhoneGap处理跨平台编码 - 因此我的代码将是HTML,CSS和JavaScript。
我遇到的主要障碍是与我的SharePoint服务器进行身份验证。 许多人在网上成功地使用了AJAX调用,但是我收到以下错误:
XMLHttpRequest cannot load http://<DOMAIN>/_vti_bin/authentication.asmx. The request was redirected to 'http://<DOMAIN>/_layouts/15/error.aspx?ErrorText=Request%20format%20is%20unrecognized%2E', which is disallowed for cross-origin requests that require preflight. 

以下是我的JavaScript代码:
function Authenticate() {
    $.support.cors = true;
    $.mobile.allowCrossDomainPages = true;

    $("#topnavcontent").append("Creating SOAP envelope...</br>");

    var soapEnv = "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"     xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
    "<soap:Body>" +
    "<Login xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">" +
    "<username>USERNAME</username>" +
    "<password>PASSWORD</password>" +
    "</Login>" +
    "</soap:Body>" +
    "</soap:Envelope>";

    $("#topnavcontent").append("Calling authenticate.asmx...</br>");

    $.ajax({
        url: "http://<DOMAIN>/_vti_bin/authentication.asmx",
        type: "POST",
        data: soapEnv,
        complete: authenticationResultSuccess,
        contentType: "text/xml; charset=\"utf-8\"",
        error: authenticationResultError
    });
}

我了解浏览器会发送一个预检OPTIONS调用。默认情况下,SharePoint网站不支持OPTIONS调用。是否有任何解决方法,例如禁用此OPTIONS调用或在SharePoint网站的webconfig中设置允许预检请求的选项?感谢您提前的帮助。


你在PhoneGap项目的config.xml中设置了<access origin="*" />吗? - Dawson Loudon
愚蠢的问题,但是你的Sharepoint服务器接受跨域请求吗? - AymKdn
@AymKdn SharePoint网站已将“Access-Control-Allow-Origin”设置为“*”。 - DrEvans
@Dawson <access origin="*" /> 已经是 config.xml 的一部分了。 - DrEvans
1个回答

1
Office 365 APIs旨在用于移动应用程序和独立Web应用程序。更多详细信息请参见:http://msdn.microsoft.com/en-us/library/office/dn605892(v=office.15).aspx 一旦您使用新的Office 365 APIs进行Azure AD身份验证,您实际上可以使用SharePoint CSOM和REST APIs进行身份验证。
您是否已经查看了Visual Studio 2013中的Cordova(PhoneGap)项目类型?当您在解决方案资源管理器中的项目节点上添加连接以连接到Office 365 API时,它会生成js文件。
很快我们将提供WoodGrove App的代码示例,该应用程序在MS TechEd NA Keynote中进行了演示,网址为http://www.github.com/OfficeDev
目前有使用此API的原生Android示例,通过Android SDK可在此处找到 https://github.com/OfficeDev/Office-365-SDK-for-Android

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接