angular 向 webapi httppost 调用发送用户对象,一旦他们到达用户对象下的 webapi 服务属性将变为 null(usrnm/pswd)
angular to webapi httppost call sends user object,Once they reach the webapi service properties under the user obj are becoming null(usrnm/pswd)
嗨,我是 Angular 的新手,
现在我从一个示例登录页面开始,该页面传递包含用户名和密码的 userEntity。
userEntity是一个object/entity是webapi.
问题:
当我点击登录按钮的 http Post 调用时,我发现 angular 调用 webapi2 服务,其中 userEntity 不为空,但对象的参数,即用户名和密码变为空。
当我尝试 post 来自 Postman /fiddler 的数据时,Web Api2 单独工作。
不确定从 angular 调用时出现了什么问题。
任何帮助将非常感激。提前致谢。
WEB API2 代码如下:
[AllowAnonymous]
[HttpPost]
[Route("AuthenticateUser", Name = "AuthenticateUser")]
public HttpResponseMessage AuthenticateUser([FromBody]userEntity userentity)
{
string username = userentity.username;
string password = userentity.password;
return Request.CreateResponse(HttpStatusCode.OK, userLibraryService.AuthenticateUser(username, password));
}
Angular 代码如下:
factory.login = function (email, password) {
return $http.post(serviceBase + 'AuthenticateUser', { userentity: { username: ’testuser@test.com', password : 'pass1335' } }).then(
function (results) {
var loggedIn = results.data.status;;
return loggedIn;
});
};
输出:
我看到 userEntity 不为空,但一旦请求到达 webapi2 服务,用户名和密码为空
尝试发送仅包含用户名和密码属性的对象:
return $http.post(serviceBase + 'AuthenticateUser', { username: 'testuser@test.com', password: 'pass1335' }).then(
function (results) {
var loggedIn = results.data.status;;
return loggedIn;
});
};
您的示例中还有 ’
而不是 '
,不确定是不是打字错误。
嗨,我是 Angular 的新手, 现在我从一个示例登录页面开始,该页面传递包含用户名和密码的 userEntity。 userEntity是一个object/entity是webapi.
问题: 当我点击登录按钮的 http Post 调用时,我发现 angular 调用 webapi2 服务,其中 userEntity 不为空,但对象的参数,即用户名和密码变为空。
当我尝试 post 来自 Postman /fiddler 的数据时,Web Api2 单独工作。 不确定从 angular 调用时出现了什么问题。 任何帮助将非常感激。提前致谢。
WEB API2 代码如下:
[AllowAnonymous]
[HttpPost]
[Route("AuthenticateUser", Name = "AuthenticateUser")]
public HttpResponseMessage AuthenticateUser([FromBody]userEntity userentity)
{
string username = userentity.username;
string password = userentity.password;
return Request.CreateResponse(HttpStatusCode.OK, userLibraryService.AuthenticateUser(username, password));
}
Angular 代码如下:
factory.login = function (email, password) {
return $http.post(serviceBase + 'AuthenticateUser', { userentity: { username: ’testuser@test.com', password : 'pass1335' } }).then(
function (results) {
var loggedIn = results.data.status;;
return loggedIn;
});
};
输出: 我看到 userEntity 不为空,但一旦请求到达 webapi2 服务,用户名和密码为空
尝试发送仅包含用户名和密码属性的对象:
return $http.post(serviceBase + 'AuthenticateUser', { username: 'testuser@test.com', password: 'pass1335' }).then(
function (results) {
var loggedIn = results.data.status;;
return loggedIn;
});
};
您的示例中还有 ’
而不是 '
,不确定是不是打字错误。