Sharepoint 2013 通过 REST API:尝试创建项目时出现错误 403 Forbidden [英] Sharepoint 2013 via REST API: Error 403 Forbidden when trying to create item

查看:26
本文介绍了Sharepoint 2013 通过 REST API:尝试创建项目时出现错误 403 Forbidden的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Sharepoint 2013 上的其余 api 创建一个简单的列表项.我的代码:

I'm trying to create a simple list item with the rest api on Sharepoint 2013. My code:

$.ajax({
    url: siteUrl + "/_api/web/lists/getByTitle('internal_Listname')/items",
    type: "POST",
    contentType: "application/json;odata=verbose",
    data: JSON.stringify({
         '__metadata': {
            'type': 'SP.Data.internal_ListnameListItem',
         },
         'K1F1': k1f1Result,
    }),
    headers: {
        "accept": "application/json;odata=verbose",
        "X-RequestDigest": $("#__REQUESTDIGEST").val(),
    },
    success: function (data) {
        console.log("done");
    },
    error: function (err) {
        console.log(JSON.stringify(err));
    }
});

尝试发送数据时,我收到 403禁止"错误.

When trying to send the data I get the 403 "Forbidden" error.

"error":{
   "code":"-2130575251, Microsoft.SharePoint.SPException",
   "message":{
        "lang":"en-US",
        "value":"The security validation for this page is invalid and might be corrupted. Please use your web browser's Back button to try your operation again."
    }
}

  • 我拥有此站点和列表的完全管理员权限.
  • 推荐答案

    前几天找到了解决方案:我忘了将请求摘要表单添加到正文中.它应该具有以下结构;

    Found the solution a few days ago: I forgot to add the request digest form to the body. It should have the following structure;

    <form runat="server">
       <SharePoint:FormDigest ID="FormDigest1" runat="server"></SharePoint:FormDigest>
    </form>
    

    这篇关于Sharepoint 2013 通过 REST API:尝试创建项目时出现错误 403 Forbidden的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆