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

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

本文关键字:结果 取错误 获取 外部 web 服务 调用 Alfresco      更新时间:2023-09-26

Alfresco社区版-5.1.x。当调用外部web服务时,我得到错误,无法获得结果

代码:

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共享UI调用Alfresco Webscript时遇到了这个问题,并发现问题是在Alfresco平台CORS配置中。默认情况下,我们的Alfresco.util.Ajax.request包含以下请求头:

  • localtoken
  • x-requested-with

这些必须包含在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 all-in-one-platform-docker容器时,要在alfresco-global.properties中进行配置。如果在Tomcat或其他应用服务器中部署自己的WAR,则需要遵循特定于该系统的说明。