我已经创建并部署了自己的网络服务 (WCF C#)。我想使用 JavaScript 调用它,获取数据并填充图表。
这是我粘贴在汇流中的代码 HTML macro :
<script>
function fun()
{
var request = $.ajax({
url: "http://mydomain:port/MyService.svc/testRest",
data: "m=aa",
processData: true,
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
console.log(response);
},
error: function (e) {
console.log('error ' + e.status + ' ' + e.responseText);
}
});
}
var x = fun();
console.log(x);
</script>
我在 Google Chrome (F12) 上通过开发者控制台收到的错误:
Mixed Content: The page at 'https://myconfluencesite.com/mypage' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://mydomain:port/MyService.svc/testRest?m=aa'. This request has been blocked; the content must be served over HTTPS.
我已经 whitelisted 服务 URL http://mydomain:port/MyService.svc/testRest 。假设我在我的域上激活 SSL,这会解决问题吗?有没有更好的方法?
主要思想是用外部数据加载/填充表格/图表。所以我首先从我自己的服务开始,它返回一个 JSON 结构。如果可行,我就可以使用该结构来填充/加载 HighCharts 组件,例如。
最佳答案
将 http://mydomain:port/MyService.svc/testRest
更改为 https://mydomain:port/MyService.svc/testRest
。 Google Chrome 浏览器确实不喜欢您通过 https 提供页面,然后使用 http 调用服务。所以,是的,激活 SSL 并使用它 将解决这个问题。我什至会说任何服务都不应该使用非安全通道。让您的服务需要 ssl。
关于javascript - 从 Confluence 调用自定义 REST API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49387103/