我想为工作中的 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 中的设置将允许飞行前通过。预先感谢您的帮助。
最佳答案
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 示例通过此处的 Android SDK 使用此 API https://github.com/OfficeDev/Office-365-SDK-for-Android
关于javascript - 为 SharePoint 2013 创建跨平台移动应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21687814/