【问题标题】:Creating a Cross-Platform Mobile Application for SharePoint 2013为 SharePoint 2013 创建跨平台移动应用程序
【发布时间】:2014-06-04 07:34:02
【问题描述】:

我想在工作中为我的 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 中允许飞行前通过的设置。提前感谢您的帮助。

【问题讨论】:

  • 您是否在您的 config.xml 中为 phonegap 项目设置了&lt;access origin="*" /&gt;
  • 愚蠢的问题,但是您的 Sharepoint 服务器是否接受跨域请求?
  • @AymKdn SharePoint 网站的“Access-Control-Allow-Origin”设置为“*”。
  • @Dawson &lt;access origin="*" /&gt; 已经是 config.xml 的一部分。

标签: javascript android sharepoint cordova


【解决方案1】:

Office 365 API 旨在用于移动应用程序和独立 Web 应用程序。更多细节在这里:http://msdn.microsoft.com/en-us/library/office/dn605892(v=office.15).aspx

在使用新的 Office 365 API 通过 Azure AD 进行身份验证后,您实际上可以将 SharePoint CSOM 和 REST API 与身份验证承载一起使用。

您是否检查过 Visual Studio 2013 中的 Cordova (PhoneGap) 项目类型?当您在解决方案资源管理器中的项目节点中添加连接以连接到 Office 365 API 时,这会生成 js 文件。

很快我们就会在http://www.github.com/OfficeDev 的 MS TechEd NA 主题演讲中获得 WoodGrove 应用程序的代码示例。

目前有通过 Android SDK 使用此 API 的原生 Android 示例https://github.com/OfficeDev/Office-365-SDK-for-Android

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-10
    • 2011-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    相关资源
    最近更新 更多