最近,需要在SharePoint上傳檔案到檔案庫,但是,上傳的程序報錯了,
錯誤代碼
{ "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." } }}
操作就是呼叫SharePoint Plus 添加檔案
https://aymkdn.github.io/SharepointPlus/files.html#createFile
有興趣的可以看一下這個插件,本來以為是插件的問題,后來發現并不是,
發現插件在執行這個方法的時候,其實是Call REST Service,
然后,呼叫了REST API上傳,也是報一樣的錯誤,
后來發現,是Request Digest token需要重繪一下:
$.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/contextinfo", method: "POST", headers: { "Accept": "application/json; odata=https://www.cnblogs.com/jianyus/p/verbose"}, success: function (data) { $('#__REQUESTDIGEST').val(data.d.GetContextWebInformation.FormDigestValue) }, error: function (data, errorCode, errorMessage) { alert(errorMessage) }});
執行完上面的代碼以后,就可以正常上傳檔案了,完事兒以后,有想了想為什么,可能是因為根網站集呼叫同web application下其他網站集吧,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/2330.html
標籤:SharePoint
下一篇:dubbo初識
