javascript - 从 Confluence 调用自定义 REST API

标签 javascript c# rest asp.net-web-api confluence

我已经创建并部署了自己的网络服务 (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 组件,例如。

enter image description here

最佳答案

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/

相关文章:

javascript - d3.js transition().remove() 不工作

javascript - 使用 Grunt 解析和构建的不同方法

JavaScript 预加载音频

c# - 用户 '' 登录失败,无法打开登录请求的数据库 "Database1.mdf"。登录失败。用户 'rBcollo-PC\rBcollo' 登录失败

JSON、REST、SOAP、WSDL 和 SOA : How do they all link together

javascript - 如何引用单引号和双引号中已经存在的文本?

c# - Windows 窗体 (WinForms) 模型 View View 模型模式 (MVVM) 是否进行数据绑定(bind)

c# - C# 中的 Java 三重移位运算符 (>>>) 的等价物?

java - 在 Java 中使用 Jersey 时出现错误 $ErrorMessagesException

php - 按 Yii2 RESTful API 上的其他字段过滤