向ewsURL发出请求时Outlook外接程序获取CORS [英] Outlook Addin getting CORS when making request to ewsURL

查看:18
本文介绍了向ewsURL发出请求时Outlook外接程序获取CORS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个Outlook外接程序,它向ewsURL发出AJAX请求。

以下是我如何请求ewsUrl:

的示例
Office.context.mailbox.getCallbackTokenAsync(function(result) {
  var token = result.value;
  var ewsurl = Office.context.mailbox.ewsUrl;
  var itemId = Office.context.mailbox.item.itemId;
  var envelope = getSoapEnvelope(itemId); // builds soap request

  var xhttp = new XMLHttpRequest();
  xhttp.open("POST", ewsurl, true);
  xhttp.setRequestHeader("Content-type", "application/soap+xml");
  xhttp.setRequestHeader("Authorization", "Bearer " + token);
  xhttp.send(envelope);

  xhttp.onload = function() {
  // never comes here
  };

  xhttp.onprogress = function(event) {
  // never comes here
  };

  xhttp.onerror = function() {
  // COMES HERE IMMEDIATELY and ERROR ABOUT CORS IN CONSOLE
  };
});

给我抛出CORS问题

访问XMLHttpRequest,地址为 发源‘https://outlook.office365.com/EWS/Exchange.asmx’ ‘https://myorg.github.io’已被CORS策略阻止:响应 印前检查请求未通过访问控制检查:否 "Access-Control-Allow-Origin"标头位于请求的 资源。

这是控制台中网络选项卡上的外观

我已在应用程序域中将‘https://myorg.github.io’添加到我的清单中

<AppDomains>
  <AppDomain>https://metz-dk.github.io</AppDomain>
</AppDomains>

但是,这并没有改变任何事情。

如果我尝试执行邮递员的请求,事情将按预期进行,以下是响应头(不确定是否有帮助)

cache-control: private
transfer-encoding: chunked
content-type: text/xml; charset=utf-8
server: Microsoft-IIS/10.0
request-id: bfac7074-180b-2e3d-2a55-94525741a78d
alt-svc: h3=":443",h3-29=":443"
x-calculatedfetarget: AS9PR06CU014.internal.outlook.com
x-backendhttpstatus: 200; 200
set-cookie: exchangecookie=hash32chars; path=/; secure
x-feproxyinfo: AS9PR06CA0415.EURPRD06.PROD.OUTLOOK.COM
x-calculatedbetarget: AM7P191MB0851.EURP191.PROD.OUTLOOK.COM
x-rum-validated: 1
x-ms-appid: a18de30c-141b-4967-90a6-793df473fcb0
x-ewshandler: GetItem
x-aspnet-version: 4.0.30319
x-besku: WCS6
x-diaginfo: AM7P191MB0851
x-beserver: AM7P191MB0851
x-proxy-routingcorrectness: 1
x-proxy-backendserverstatus: 200
x-feserver: AS9PR06CA0415; GV3P280CA0046
x-firsthopcafeefz: GVX
x-powered-by: ASP.NET
date: Tue, 23 Nov 2021 14:13:22 GMT

您知道可能出了什么问题吗?

谢谢。

推荐答案

我无法解决CORS的原始问题,但我遵循了@outlookAdd-insTeam-msft的建议,并将拉取电子邮件的逻辑移动到我的服务器(无论如何电子邮件都必须存储在服务器上)。因此,代码现在运行在服务器上,而不是前端(插件)。

这篇关于向ewsURL发出请求时Outlook外接程序获取CORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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