我有点卡住了,我想征求你的意见,我正在尝试使用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}}
http://prntscr.com/hate2e
更新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);
}
});
},