ajax获取Office365 REST Api请求失败CORS?
发布时间:2020-12-16 01:37:30 所属栏目:百科 来源:网络整理
导读:我正在尝试从本地服务器向Office365 RESTful API服务发出ajax GET请求,但是遇到了跨域HTTPRequest错误.以下是我的’get-files-at-root’尝试的示例: $.ajax({ url: 'https://[sharepoint_site]/_api/v1.0/me/files?access_token='+token,type: 'get',dataTy
我正在尝试从本地服务器向Office365 RESTful API服务发出ajax GET请求,但是遇到了跨域HTTPRequest错误.以下是我的’get-files-at-root’尝试的示例:
$.ajax({ url: 'https://[sharepoint_site]/_api/v1.0/me/files?access_token='+token,type: 'get',dataType: 'json',success: function(data) { if (success){ success(data); } },error: error }) 我从服务器得到以下响应: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 403. 我尝试将访问令牌作为标头参数发送: headers: {'Authorization': 'Bearer '+ token} 但这也有同样的结果. 关于我做错的任何想法? (背景:我正在尝试在客户端上创建自己的Office365’文件选择器’,因为我找不到提供此功能的OneDrive Business的可用库.)
Office 365 Files API和SharePoint REST刚刚引入了对CORS的支持.
https://msdn.microsoft.com/en-us/office/office365/howto/create-web-apps-using-CORS-to-access-files-in-Office-365 你想要做的就是它的工作原理.该服务将使用Access-Control-Allow-Origin标头响应OPTIONS飞行前请求. 请求中的授权必须是Azure Active Directory颁发的OAuth2隐式授权访问令牌. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |