我想将用户名从angular发布到asp.net Web api。我从服务器发布的方法是:
[Route("CheckUserName")]
[AllowAnonymous]
[HttpPost]
public async Task<IHttpActionResult> CheckUsernameExist([FromBody] string username){ //return true or false}
和斜角
checkUserName(userName: string) {
return this.http.post(
`${this.appConfig.apiEndpoint}/${CHECK_USER_NAME}`,{userName})
.pipe(map(res => res['result']['status'] as boolean));}
{userName}是要发送到服务器的数据但是服务器端收到null我也测试数据:
userName,
{username:userName},
'"'+userName+'"',
,...
checkUserName(userName: string) {
const headers = new HttpHeaders();
headers.append('Content-Type', 'application/json');
return this.http.post(
`${this.appConfig.apiEndpoint}/${CHECK_USER_NAME}`, { userName },{ headers: headers })
.pipe(map(res => res['result']['status'] as boolean));
}
以这种格式发送数据:
{userName:userName}