繁体   English   中英

Alfresco:外部 Web 服务调用获取错误无法获得结果?

[英]Alfresco : External Webservice calling gettting error not able to get result?

Alfresco 社区版-5.1.x。 调用外部网络服务时出现错误,无法获得结果

代码:

function updateList(){
    Alfresco.util.Ajax.request({

                url: "http://test.com/webservice/mgmobile/mgserver.php?wsfunction=course_get_all_courses&wstoken=7f5e0f05f7c54ece7a23f02fe3718464",
        method: Alfresco.util.Ajax.GET,

                headers: ('Access-Control-Allow-Origin: *'),
                headers: ('Access-Control-Request-Headers: *'),
                headers: ('Access-Control-Allow-Methods: *'),
        requestContentType: Alfresco.util.Ajax.JSON,
        successCallback:{
            fn: function(res){  
                appendOptiOnvalues(res)
            },
        },
        failureCallback:{
            fn: function(res){  
                alert("Error");
            },
        }
    });

}

错误:

跨域请求被阻止:同源策略不允许在http://test.com/webservice/mgmobile/mgserver.php?wsfunction=course_get_all_courses&wstoken=7f5e0f05f7c54ece7a23f02fe3718464读取远程资源。 (原因:CORS 预检通道的 CORS 标头“Access-Control-Allow-Headers”中缺少令牌“content-type”)。

请帮忙解决这个问题。

看起来调用是对非 Alfresco 服务器进行的,因此在 Alfresco 上配置 CORS 无济于事。 相反,请检查您正在调用的服务器上的 CORS 配置,并确保它设置了“Access-Control-Allow-Headers”以允许指定“content-type”标头。 这可能是由您正在使用的 Alfresco AJAX util 库设置的。

我不知道您正在调用哪个服务器,因此我无法提供特定于该服务器的 CORS 帮助,但这里有一些有关为各种类型的服务器启用 CORS 的信息。

我们今天在尝试从 Alfresco Share UI 调用 Alfresco Webscript 时遇到了这个问题,发现问题出在 Alfresco Platform CORS 配置中。 我们的Alfresco.util.Ajax.request默认包含以下请求头:

  • 本地令牌
  • x 请求

这些必须包含在alfresco-global.properties中的cors.allowed.headers属性中,否则请求将被 ACS 以 HTTP 403 拒绝。

示例

cors.enabled=true
cors.allowed.origins=http://localhost:8180
cors.allowed.methods=GET,HEAD,POST,PUT,DELETE,OPTIONS
cors.allowed.headers=origin, authorization, x-file-size, x-file-name, content-type, accept, x-file-type, range, localtoken, x-requested-with
cors.support.credentials=true
cors.exposed.headers=Accept-Ranges, Content-Encoding, Content-Length, Content-Range, content-type, localtoken

笔记
请记住,在使用 Alfresco 提供的 ACS 多合一平台 docker 容器时,您可以在alfresco-global.properties中进行配置。 如果在 Tomcat 或其他应用程序服务器中部署您自己的 WAR,您需要遵循特定于该系统的说明。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM