使用 Chrome 的 restful 查询工具 Postman,我可以执行以下 POST 请求而没有错误:(注意 - 此处添加了括号)
http://[myserver]/direct/session?_username=[usr]&_password=[pwd]
为什么我的 Angular 工厂中完全相同的查询总是失败?
MyApp.factory('sessionFactory', function($http) {
var factory = {};
factory.authenticate = function(u,p) {
var params = {
_username:u,
_password:p
};
var url = "[myserver]/direct/session?_username=[usr]&_password=[pwd]";
$http.post(url)
.success(function (data, status, headers, config) {
console.log("Success " + status);
})
.error(function (data, status, headers, config) {
console.log("Error " + status + config.toString() + data.toString() + headers.toString());
});
};
return factory;
});
Firebug 控制台报告:
"NetworkError: 400 Bad Request - http://[myhost]/direct/session?_username=[usr]&_password=[pwd]"
Error 0[object Object]function (name) {
“使用严格”;
if (!headersObj) headersObj = parseHeaders(headers);
if (name) {
return headersObj[lowercase(name)] || null;
}
return headersObj;