我在Confluence用户宏中调用JavaScript中的JIRA REST API,我正面临CORS问题,因为JIRA和Confluence位于两个不同的域,并且来自浏览器的preflight request失败。我尝试了几种CORS解决方案,如下所述,没有任何成功。所以林乞求从其他人可能已经解决了这个问题的一些意见。在JIRA REST API中启用CORS
的JavaScript代码段失败:
AJS.$.ajax({
type: "GET",
url: "http://jira.mydomain.com/rest/api/latest/search/?jql=issue%20in%20linkedIssues(SR-45)",
dataType: "json",
contentType: "application/json",
async: false
})
错误消息(从Firefox):
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://jira.mydomain.com/rest/api/latest/search/?jql=issue%20in%20linkedIssues(SR-45). This can be fixed by moving the resource to the same domain or enabling CORS.
JIRA配置
- JIRA版本:6.4.12
- 网址:http://jira.mydomain.com
- 跑在最前面的Apache(代理):是
- 响应头配置:
Access-Control-Allow-Headers:origin, content-type, accept
Access-Control-Allow-Methods:POST, GET, OPTIONS
Access-Control-Allow-Origin:*
- 响应头配置:
- 合流加入到whitelist:是
- 表达:总汇(http://confluence.mydomain.com)
- 类型:应用程序链接
- 允许传入:真
合流配置
- Confluence版本:5.8。8
- 地址:http://confluence.mydomain.com
- 在前面运行的Apache(代理):是
- 响应头配置:
Access-Control-Allow-Origin:*
- 响应头配置:
- JIRA加到whitelist:是
- 表达:总汇(http://jira.mydomain.com)
- 类型:应用程序链接
- 允许传入:真
测试用的浏览器:
- 铬(最新)
- Safari(最新版)
- 火狐(最新)
测试预检要求(期权),卷曲:
ismar.slomic$ curl -X OPTIONS "http://jira.mydomain.com/rest/api/latest/search/?jql=issue%20in%20linkedIssues(SR-45)" -v
* Trying 10.107.1.24...
* Connected to jira.mydomain.com (127.0.0.1) port 80 (#0)
> OPTIONS /rest/api/latest/search/?jql=issue%20in%20linkedIssues(SR-45) HTTP/1.1
> Host: jira.mydomain.com
> User-Agent: curl/7.43.0
> Accept: */*
>
* Empty reply from server
* Connection #0 to host jira.mydomain.com left intact
curl: (52) Empty reply from server
这似乎是积极的回应。
测试预检要求(期权)与克罗姆extention Postman:
OPTIONS http://jira.mydomain.com/rest/api/latest/search/?jql=issue%20in%20linkedIssues(SR-45)
响应的错误:Could not get any response. This seems to be like an error connecting to http://jira.mydomain.com/rest/api/latest/search/?issue%20in%20linkedIssues(SR-45)
您是否在Chrome上得到了与Firefox相同的错误消息? – rby
Chrome中的错误消息:NetworkError:未能在'XMLHttpRequest'上执行'发送':未能加载'http://jira.mydomain.com/rest/api/latest/search/?jql=issue%20in%20linkedIssues。 .. –
它看起来像你的ajax电话没有经过。也许你可以添加一个错误回调,并看看你得到的状态。另外,您将json指定为dataType,因此请确保您确实正在发送json数据。 – rby