问题描述
Microsoft文档声明“您的自定义功能将具有完整的CORS支持。”在共享运行时中运行时。参见https://docs.microsoft.com/en-us/office/dev/add-ins/excel/custom-functions-shared-overview 和 https://docs.microsoft.com/en-us/office/dev/add-ins/excel/configure-your-add-in-to-use-a-shared-runtime 但是,我无法从在共享运行时中运行的自定义函数发送跨源POST请求。它总是抛出网络请求失败。似乎只能使用相同的来源或简单的GET。 这是我尝试使用提取(在自定义函数外部验证工作)的示例代码。
fetch('example.com',{
method: 'POST',headers: {
'Content-Type': 'application/json',},body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => {
console.log('Success:',data);
})
.catch((error) => {
console.error('Error:',error);
throw error;
});
也尝试使用XMLHttpRequest()
,但对于status=0
也总是失败。如果有人设法从自定义函数发出完整的CORS POST请求(如文档所述),则可以,请分享一个有效的示例。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)