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

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

问题描述

我正在尝试使用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));
    }
});

尝试发送数据时,我收到403Forbidden错误。

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在尝试创建项目时被禁止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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