我需要以字符串形式从API调用获取响应。 我的API函数很简单(用于测试)
[HttpPost("verifyCode")]
public ContentResult verifyCode([FromBody] UserM resetModel)
{
return "This is response";
}
API调用
verifyCode(username, code){
const body = 'username=' + username + '&code=' + code;
let test = new UserM();
test.username = username;
test.code = code;
const requestHeaders: HttpHeaders = new HttpHeaders({
'Content-Type': 'application/json;charset=utf-8'
});
return this.http.post<string>('http://localhost:12763/api/account/verifyCode/', test, {headers: requestHeaders, withCredentials: true});
}
我正在尝试在此处获取输出
this.userService.verifyCode(username,code).subscribe(
(data)=>{
console.log(data);
}
)
但是我没有在控制台上得到输出,但是得到了这个错误
SyntaxError:JSON位置0上的意外令牌R
答案 0 :(得分:0)
更改您的后端响应,然后尝试使用
[HttpPost("verifyCode")]
public ContentResult verifyCode([FromBody] UserM resetModel)
{
return ContentResult ("This is response","text/plain",Encoding.UTF8);
}