尝试使用 SharePoint 2013 的 REST 服务器和 CSOM 时,“未为此应用程序的请求 URL 部署应用

"App Web is not deployed for this app's request url" when trying to use SharePoint 2013's REST server and CSOM

本文关键字:应用程序 应用 部署 URL 请求 CSOM SharePoint 2013 REST 服务器      更新时间:2023-09-26

获取 SharePoint 列表数据我通过 CSOM 访问 REST 服务器时遇到问题。我已经在CSOM和仅使用jQuery上尝试过这个。下面的代码示例和相关错误。谁能指导我到一个工作的例子或告诉我我做错了什么?

此代码是 SharePoint 托管应用程序的一部分,列表只是根 Web 中的一个列表。用户有权访问列表和应用。

CSOM 示例: 收益 率: 失败!:未为此应用的请求 URL http://mySharePointRootWebURL.local 部署应用 Web。

var data = new SP.RequestExecutor("http://mySharePointRootWebURL.local/");
data.executeAsync({
    method: "GET",
    headers: { "Accept": "application/json;odata=verbose" },
    url: "http://mySharePointRootWebURL.local/_api/web/lists/getbytitle(''MyLstName'')/items",
    success: function (data) { console.log('success!'); },
    error: function (p1,p2,errorMessage) { console.log('Fail! :' + errorMessage); }
    });

我可以看到这个例子根本没有击中根网络(从应用程序/应用程序网络)。


j查询示例收益 率:资源解释为脚本,但使用 MIME 类型文本/纯文本传输:"http://mySharePointRootWebURL.local/_api/web/lists/getbytitle('''MyLstName''')/items&...Query19104068602353800088_1379462071044&alt=json-in-script&_=1379462071045"。jquery.js:9597未捕获的语法错误:意外的令牌<项:1失败!:错误:未调用jQuery19104068602353800088_1379462071044>

$.ajax({ 
    url: "http://mySharePointRootWebURL.local/_api/web/lists/getbytitle(''MyListName'')/items",
    type: "GET",
    beforeSend: function(xhr){
    xhr.setRequestHeader('Accept', 'application/json;odata=verbose'); },
    headers: {"Accept":"application/json;odata=verbose"},
    success: function(data){ console.log("success"); },
    error: function errHandler(p1,p2,errMessage){ console.log("fail! : " + errMessage); },
    dataType: 'jsonp',
    crossDomain: true,
    data: {
        alt: 'json-in-script'
    },
});

这在访问 REST 服务器和返回数据方面有效,问题是根本没有添加标头(在 Fiddler 中验证)。如果没有标头,数据将以 XML 形式返回。如果这就是它必须的方式,我会使用它,我猜,但我更愿意得到 JSON。

你的代码看起来不对。这是与跨域库相关的代码

   var executor = new SP.RequestExecutor(appweburl);
    executor.executeAsync(
    {
        url:
        appweburl +
        "/_api/SP.AppContextSite(@target)/web/lists/getByTitle('Contacts')/items" +
                        "?@target='" + hostweburl + "'" +
                        "&$select=Id,FirstName,Title,WorkPhone,Email" +
                        "&$orderby=Title,FirstName",
        method: "GET",
        headers: { "accept": "application/json;odata=verbose" },
        success: successHandler,
        error: errorHandler
    })