'访问控制允许起源'访问托斯卡的REST API [英] 'access-control-allow-origin' accessing rest api of Tosca
本文介绍了'访问控制允许起源'访问托斯卡的REST API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从服务器上调用Tosca的rest api,这给了我这个例外:"access-control-allow-origin".由于我无法控制Tosca的响应,因此有办法解决这种异常吗?
I am trying to call Tosca's rest api from my server and it's giving me this exception: 'access-control-allow-origin'. Since I have no control over Tosca's response, is there a way to get around this exception?
推荐答案
Most likely the issue is not related to Tosca REST API, rather is a CORS problem. So, I am assuming your web server and the Tosca REST API server are on different domain. You can basically bypass this problem by allowing cross-origin requests from the web application, by adding the following configuration to the web.config
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET, POST" />
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
这篇关于'访问控制允许起源'访问托斯卡的REST API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文