连接datapower和worklight客户端

时间:2013-08-01 16:41:32

标签: ajax ibm-mobilefirst ibm-datapower

我尝试使用主js上使用此代码的客户端使用$ .ajax()连接worklight应用程序和数据权限:

function authDP(username, password) {

$.ajax("http://192.168.44.201:2051/cotizador", {
    success : function() {
        var invocationData = {
            adapter : "B2CAdapter",
            procedure : "setUserIdentity",
            parameters : [ username, password ]
        };
        myChallengeHandler.submitAdapterAuthentication(invocationData, {});
        alert("Login correcto");
    },
    error : function(xhr, status, error) {
        alert("Failed: " + status + " ; " + error);
    },
    headers : {

        "Authorization" : "Basic "
                + Base64.encode(username + ":" + password)


    }
});

}

但Chrome控制台会返回此信息(在chrome上):

OPTIONS http://192.168.44.201:2051/cotizador 401 (Unauthorized) wljq.js:8542
OPTIONS http://192.168.44.201:2051/cotizador Origin http://pc-ayi-0204:10080 is not      allowed by Access-Control-Allow-Origin. wljq.js:8542
XMLHttpRequest cannot load http://192.168.44.201:2051/cotizador. Origin http://pc-ayi-0204:10080 is not allowed by Access-Control-Allow-Origin. 

这是在firefox:

[11:55:22.272] OPTIONS http://192.168.44.201:2051/cotizador [HTTP/1.1 401 Unauthorized 38ms]

标题上是否有遗漏?因为在firefox控制台/ request / headers /部分中我只看到这个:

User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0
Origin:http://pc-ayi-0204:10080
Host:192.168.44.201:2051
Connection:keep-alive
Access-Control-Request-Method:GET
Access-Control-Request-Headers:authorization
Accept-Language:es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding:gzip, deflate
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

我没有看到Basic用户:传递值,这是正确的吗?

2 个答案:

答案 0 :(得分:0)

您不能使用AJAX从客户端在域外进行任意请求。例如见:

Origin is not allowed by Access-Control-Allow-Origin

答案 1 :(得分:0)

我正在尝试查看以下错误

OPTIONS http://192.168.44.201:2051/cotizador 401 (Unauthorized) wljq.js:8542 OPTIONS http://192.168.44.201:2051/cotizador **Origin http://pc-ayi-0204:10080 is not allowed by Access-Control-Allow-Origin.** wljq.js:8542 XMLHttpRequest cannot load http://192.168.44.201:2051/cotizador. Origin http://pc-ayi-0204:10080 is not allowed by Access-Control-Allow-Origin.

我不确定你在datapower [MPGW或Web服务代理]上调用了什么构造,但无论它是什么,它似乎都在其Front Side Handler上应用了ACL。该ACL定义了允许调用该构造的IP地址。我不确定您的方案中的确切用例是什么,但要纠正从Datapower Front Side Handler对象中删除ACL所需的问题。

  • Ajitabh