.net 向服务器发送请求时如何传递参数值 返回this.http.post(`${environment.apirl}/api/users/logiuser/`,{UserName,Password})
我尝试向链接传递参数,但当请求转到服务器时,参数值保持为空。.net 向服务器发送请求时如何传递参数值 返回this.http.post(`${environment.apirl}/api/users/logiuser/`,{UserName,Password}),.net,angular,asp.net-mvc,api,asp.net-core,.net,Angular,Asp.net Mvc,Api,Asp.net Core,我尝试向链接传递参数,但当请求转到服务器时,参数值保持为空。登录(用户名:字符串,密码:字符串){ return this.http.post<User>(`${environment.apiUrl}/api/users/LoginUser/`, { UserName, Password }) const headers=new-HttpHeaders().set('Content-Type','application/json'); 变量体={ “用户名”:用户名, “密码”:密
登录(用户名:字符串,密码:字符串){
return this.http.post<User>(`${environment.apiUrl}/api/users/LoginUser/`, { UserName, Password })
const headers=new-HttpHeaders().set('Content-Type','application/json');
变量体={
“用户名”:用户名,
“密码”:密码
}
返回此.http.post(`${environment.apiUrl}/api/users/LoginUser/`,正文
,{
withCredentials:null,
标题:标题,
})
}
.net
[HttpPost]
[路由(“登录用户”)]
//[EnableCors(“AllowOrigin”)]
公共响应对象登录用户(用户)
{
UsersBLL bll=新的UsersBLL();
User User=bll.LoginUser(User.UserName,User.Password);
string Token=Common.JwtHelper.CreateToken(user.Id.ToString(),user.Email);
user.Token=Token;
bll.UpdateUser(用户);
返回svcsresponse.successresponse(用户);
}
[HttpPost]
[路由(“登录用户”)]
//[EnableCors(“AllowOrigin”)]
公共响应对象登录用户(字符串用户名、字符串密码)
{
UsersBLL bll=新的UsersBLL();
User User=bll.LoginUser(用户名、密码);
string Token=Common.JwtHelper.CreateToken(user.Id.ToString(),user.Email);
user.Token=Token;
bll.UpdateUser(用户);
返回svcsresponse.successresponse(用户);
}
下面是asp.net核心中的服务器端代码在您接受请求的api中没有足够的共享代码,我在body参数中没有看到json格式。请共享更多代码登录(用户名,密码){debugger;返回此.http.post(
${environment.apirl}/api/users/LoginUser/
,{UserName,Password}).pipe(map(user=>{//在本地存储中存储用户详细信息和jwt令牌,以保持用户在页面刷新localStorage之间登录。setItem('user',JSON.stringify(user));this.userSubject.next(user);return user;}));}这是有角度的代码,我指的是web api中的代码。添加到“请提问”而不是“评论”在“问题”中添加此代码,这非常有用。
login(userName:string, password:string) {
const headers = new HttpHeaders().set('Content-Type', 'application/json');
var body = {
"UserName": userName,
"Password": password
}
return this.http.post<User>(`${environment.apiUrl}/api/users/LoginUser/`, body
,{
withCredentials: null,
headers: headers,
})
}
.net
[HttpPost]
[Route("LoginUser")]
//[EnableCors("AllowOrigin")]
public ResponseObject<User> LoginUser(User user)
{
UsersBLL bll = new UsersBLL();
User user = bll.LoginUser(user.UserName, user.Password);
string Token = Common.JwtHelper.CreateToken(user.Id.ToString(), user.Email);
user.Token = Token;
bll.UpdateUser(user);
return SvcResponse.SuccessReponse<User>(user);
}
[HttpPost]
[Route("LoginUser")]
//[EnableCors("AllowOrigin")]
public ResponseObject<User> LoginUser(string UserName, string Password)
{
UsersBLL bll = new UsersBLL();
User user = bll.LoginUser(UserName, Password);
string Token = Common.JwtHelper.CreateToken(user.Id.ToString(), user.Email);
user.Token = Token;
bll.UpdateUser(user);
return SvcResponse.SuccessReponse<User>(user);
}