我使用此代码传递IMC服务器并验证我的WL 6.2服务器(WL服务器不需要任何身份验证)。
PADMAppRealmChallengeHandler.loginToImc = function(userid,password){
PADMAppRealmChallengeHandler.writeMessage("Authenticating with w3 IMC server ...");
PADMAppRealmChallengeHandler.writeMessage("Called loginToImc ...");
if (byPassIMC)
{
}
else
{
base64uid = window.btoa(userid + ":" + password);
// var WgSessionKey = WLJQ.cookie("WgSessionKey");
alert("Cookies are: " + document.cookie );
// alert("WgSessionKey=" + WgSessionKey);
WLJQ.ajax({
url: IMCURL,
method: "get",
async: false,
cache : false,
crossDomain : true ,
headers : {
"Authorization": "Basic " + base64uid
//, "Cookie" : "WgSessionKey=XXXXX"
},
dataType: "text",
error: function(jqXHR, status, error) {
console.log("status =" + status + " error=" + error);
console.log(jqXHR);
console.log("AllResponseHeaders");
console.log("================================");
console.log( jqXHR.getAllResponseHeaders() );
PADMAppRealmChallengeHandler.writeError("Failed to authenticate. Please try again later");
console.log("============== error responseText ==================");
console.log( jqXHR.responseText);
console.log("================================");
PADMAppRealmChallengeHandler.setBusy(false);
},
timeout: 12000,
success : function(data, textStatus, jqXHR) {
console.log("================================");
PADMAppRealmChallengeHandler.writeMessage("IMC SUCC ");
console.log("================================");
console.log(jqXHR);
console.log("AllResponseHeaders");
console.log("================================");
console.log( jqXHR.getAllResponseHeaders() );
console.log(data);
console.log("================================");
var SetCookies = jqXHR.getResponseHeader('Set-Cookie');
// alert("SetCookies=" + SetCookies );
console.log("============== success responseText ==================");
console.log( jqXHR.responseText);
console.log("================================");
// if (data == "Success!!")
if (data)
{
var options =
{
onSuccess: function(e)
{
PADMAppRealmChallengeHandler.writeMessage("Workligth Connect + IMC SUCC ");
PADMAppRealmChallengeHandler.writeMessage(JSON.stringify(e));
PADMAppRealmChallengeHandler.setBusy(false);
return;
},
onFailure: function(e)
{
PADMAppRealmChallengeHandler.writeError("Failed to authenticate with Worklight. Please try again later");
PADMAppRealmChallengeHandler.setBusy(false);
alert("Error with Workligth server " + JSON.stringify(e));
}
};
console.log("Run WL.Client.connect(options); ");
WL.Client.connect(options);
} else {
PADMAppRealmChallengeHandler.writeError("The user ID or password entered is incorrect");
alert("Failed to login on IMC server, verify your user and/or password please !!");
PADMAppRealmChallengeHandler.setBusy(false);
}
}
});
}
};
在一个好的ajax get请求之后,WL.client.connect()请求被IMC拒绝,错误401 .. unauthenticate。
问题发生在
上v6.3 |错误401 |未经测试
v6.2 |错误410 |工作!
v6.1 | WOKRS |未经测试
v5.X |工作|未经测试
似乎问题是因为WL框架没有捕获Set-Cookie WgSessionKey。它只发生在Android上。这似乎是Android上的WL 6.2上引入的一个错误
答案 0 :(得分:0)
在Worklight 6.2中,没有公开支持的访问Android cookie商店的方式。这是该平台的已知限制。
为用户提供了一种替代的,未记录的不支持的方法,以解决问题:
var req=new WLJSX.Ajax.WLRequest( ...
代替WLJQ.ajax({ ...
计划是在将来的版本中通过公共API添加适当的Android cookie商店支持。然后可以注入所需的任何东西......