我有点卡住了,我想请教您的建议,我正在尝试在 Sencha Architect 中使用 DreamFactory 设置登录窗口//身份验证,但是我几乎是初学者。
我目前的代码是:
var username = Ext.getCmp('usr').getValue(),
password = Ext.getCmp('pwd').getValue();
Ext.Ajax.defaultHeaders = {
'X-DreamFactory-Api-Key' : 'xyz',
'Content-Type' : 'application/json'
};
Ext.Ajax.request({
url: 'http://dreamfactoryaddy:8080/api/v2/user/session',
withCredentials: true,
email: username,
password: password,
cors: true,
success: function(response) {
var obj = Ext.decode(response.responseText);
Ext.Ajax.defaultHeaders = {
'X-DreamFactory-Api-Key' :
'xyz', 'Content-Type' : 'application/json', 'X-DreamFactory-Session-
Token': obj.session_token
};
console.log(obj);
},
failure: function(response) {
console.log(response.responseText);
}
});
我收到此错误:
{"error":{"code":401,"context":null,"message":"There is no valid session for the current request.","status_code":401}}
你能给我一些建议如何正确处理会话吗?
更新 2:
var username = Ext.getCmp('usr').getValue(),
password = Ext.getCmp('pwd').getValue(),
headers = {
'X-DreamFactory-Api-Key' : 'xyz',
'Content-Type' : 'application/json'
};
Ext.Ajax.setDefaultHeaders(headers);
Ext.Ajax.request({
url: 'http://chalton.swiftmedia.ca:8080/api/v2/user/session',
withCredentials: true,
jsonData: {
"email" : username,
"password" : password
},
cors: true,
success: function(response) {
var obj = Ext.util.JSON.decode(response.responseText),
newheaders = {
'X-DreamFactory-Api-Key' : 'xyz',
'Content-Type' : 'application/json',
'X-DreamFactory-Session-Token': obj.session_token
};
console.log(response.responseText);
Ext.Ajax.setDefaultHeaders(newheaders);
},
failure: function(response) {
console.log(response.responseText);
}
});
},