2014-02-10 113 views
5

我想在工作中为我的SharePoint服务器创建一个简单的CRUD跨平台移动应用程序。我使用PhoneGap来处理跨平台编码 - 因此我的代码将使用HTML,CSS和JavaScript。为SharePoint 2013创建跨平台移动应用程序

我所拥有的主要障碍是使用我的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中的设置,以允许通过预先调用。先谢谢您的帮助。

+0

你有没有设置'<访问起源= “*”/>'在你的config.xml为的PhoneGap项目使用此API目前原生的Android样? –

+0

愚蠢的问题,但您的Sharepoint服务器是否接受跨域请求? – AymKdn

+0

@AymKdn SharePoint站点将“Access-Control-Allow-Origin”设置为“*”。 – DrEvans

回答

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与auth承载一起使用。

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

很快,我们将在MS TechEd NA Keynote上演示的WoodGrove应用程序的代码示例在http://www.github.com/OfficeDev

有通过Android SDK这里https://github.com/OfficeDev/Office-365-SDK-for-Android