所以我想在我的角度申請認證後獲得工作。我參加了標題並創建了一個字符串化的主體。我也看了一些有關在郵遞員發送郵件請求的其他論壇帖子,但我無法得到它的工作。
getToken()
{
console.log('started getting of token');
//get username and password from local storage
//Send username and password via body
let headers = new Headers();
let body = JSON.stringify({
name: 'test',
password: 'test'
});
headers.append('Content-Type', 'application/x-www-form-urlencoded');
this.jwt = this.http.post('http://localhost:8080/api/authenticate/', {
headers: headers,
body: body
}).map(res => res.text()).subscribe(data => console.log(data));
}
所以上面是我的代碼。我知道這可能是一件有點愚蠢的事情,但我無法得到它的工作。 我收到用戶無法找到的錯誤。當用戶名錯誤,以及用戶名不存在於數據庫中時會發生這種情況。所以還有一點棘手。
誰知道我犯了什麼愚蠢的錯誤?
嘗試' '的Content-Type':「應用程序/ json'' –
難道不幸的是不行的,感謝您的建議:) – Nathan
調試你的API,檢查你的名字和密碼參數。 –