【问题标题】:Alfresco : External Webservice calling gettting error not able to get result?Alfresco:外部 Web 服务调用获取错误无法获得结果?
【发布时间】:2016-09-30 06:15:15
【问题描述】:

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”)。

请帮忙。

【问题讨论】:

标签: javascript alfresco alfresco-share


【解决方案1】:

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

我不知道您调用的是什么服务器,因此我无法提供特定于该服务器的 CORS 帮助,但here 是有关为各种类型的服务器启用 CORS 的一些信息。

【讨论】:

    【解决方案2】:

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

    • 本地令牌
    • x-requested-with

    这些必须包含在 alfresco-global.propertiescors.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-global.properties 是您在使用 Alfresco 提供的 ACS all-in-one-platform-docker 容器时配置它的地方。如果在 Tomcat 或其他应用程序服务器中部署您自己的 WAR,您需要遵循特定于该系统的说明。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-14
      • 1970-01-01
      相关资源
      最近更新 更多