从Outlook加载项中进行HTTP提取 [英] HTTP fetch from within Outlook add-ins

查看:75
本文介绍了从Outlook加载项中进行HTTP提取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要调用一个外部Web服务,以便我的外接程序与我们公司的Java Servlet进行通信.我尝试使用JavaScript的XMLHttpRequest:

var http = new XMLHttpRequest();
http.open( "GET", url2, true );
http.onreadystatechange = function(){
    console.log( 'Data: ' + http.responseText + '\nStatus: ' + http.status );
}

,然后将Google的主要网站指定为白名单:

<AppDomains>
    <AppDomain>https://www.google.com/</AppDomain>
</AppDomains>

尝试它是否有效,但是每次运行它,我都会得到:

Failed to load https://www.google.com/: Redirect from 'https://www.google.com/' to
'https://www.google.es/?gfe_rd=cr&dcr=0&ei=TFjDWub9No-aX5TXg7AK' has been blocked
by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'https://localhost:3000' is therefore not allowed access.

Data: attachmentsSelectionScreen.html?recordName=A:223
Status: 0

我搜索了如何针对Outlook外接程序发出跨域HTTP请求,并访问了从Outlook加载项中调用Web服务,因为其名称与我需要的名称非常相似,但仅在其中找到了有关如何与Outlook本身进行交互的信息(创建文件夹,如垃圾等.

例如,我如何简单地请求 https://www.google.com 从我的加载项中获取响应?

非常感谢您!

解决方案

您的方向确实正确.要从第三方网络服务检索信息,您需要:

  • 使用XMLHttpRequest$ajax等进行请求.
  • 将服务URL添加到清单的AppDomains列表中
  • 仅使用SSL连接(https://)下的服务

基本上,您已经完成了,您应该能够从服务中获取信息.您可能会遇到的所有其他问题都与服务本身有关,而不是与外接程序内部的呼叫有关.例如:google将您重定向到AppDomains列表下未声明的https://www.google.es.该服务本身可能无法提供任何信息,您可能会收到403响应.该服务可能不允许CORS请求,或者可以通过令牌,许可证等在某些授权下允许它.以下来源可能帮助您获得更多有关该主题的信息:

基本上,这取决于服务.这就是为什么ppl通常编写自己的服务的原因,该服务将允许加载项请求,因为他们可以完全控制该请求.该服务可以同时对其他服务进行某些子请求,以获得所需的信息.

I need to call an external web service so that my add-in communicates with our company's Java servlets. I tried using JavaScript's XMLHttpRequest:

var http = new XMLHttpRequest();
http.open( "GET", url2, true );
http.onreadystatechange = function(){
    console.log( 'Data: ' + http.responseText + '\nStatus: ' + http.status );
}

and specifying Google's main site as whitelisted:

<AppDomains>
    <AppDomain>https://www.google.com/</AppDomain>
</AppDomains>

to try if it works, but every time I run it this is what I get:

Failed to load https://www.google.com/: Redirect from 'https://www.google.com/' to
'https://www.google.es/?gfe_rd=cr&dcr=0&ei=TFjDWub9No-aX5TXg7AK' has been blocked
by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'https://localhost:3000' is therefore not allowed access.

Data: attachmentsSelectionScreen.html?recordName=A:223
Status: 0

I searched how to make an cross-origin HTTP request specifically for Outlook add-ins and came to Call web services from an Outlook add-in, given how closely its name resembles what I needed, but only found there information about how to interact with Outlook itself (create folder, mark as junk, etc.).

How can I, for instance, make a simple request to https://www.google.com from my add-in and fetch the response?

Thank you so so much!

解决方案

You are on the right direction, indeed. To retrieve information from 3rd party web service, you would need:

  • Make request with XMLHttpRequest or $ajax, etc.
  • Add the service URL into manifest's AppDomains list
  • Use only services which are under SSL connection (https://)

Basically you are done, you should be able to get the information from the service. All other issues you may experience related to the service itself, not your calls from inside of the add-in. For example: google redirects you to the https://www.google.es which is not declared under your AppDomains list. The service itself may not be available to provide with any information and you may get 403 response. The service may not allow CORS requests or may allow it under certain authorization via tokens, licenses, etc. The following sources may help you to get more on the topic:

Basically this is up to the service. This is the reason why ppl are usually write their own service, which will allow the add-in request, because they have full control over it. This service in the same time may do certain sub-requests to other services to get required information.

这篇关于从Outlook加载项中进行HTTP提取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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