[英]How to receive a string as a return from an API call in angular?
我需要以字符串的形式從我的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:位於0的JSON中的意外標記R.
更改后端響應並嘗試它將起作用
[HttpPost("verifyCode")]
public ContentResult verifyCode([FromBody] UserM resetModel)
{
return ContentResult ("This is response","text/plain",Encoding.UTF8);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.