如果您使用的HttpClient而不是HTTP代碼應該是這樣的:
login(credintials: Authenticate): Observable<any> {
const body = {
username: credintials.username,
password: credintials.password,
grant_type: 'password',
client_id: credintials.client_id
};
const headers = new HttpHeaders()
.set('Content-Type', 'application/x-www-form-urlencoded')
.set('Authorization', 'Basic loremlorem');
return this.http.post(`${baseUrl}/uaa/oauth/token`,
body,
{
headers: headers
}
);
}
如果params爲可選你應該添加這樣的參數:
let params: HttpParams = new HttpParams();
if (param) {
params = params.append('page', param.page);
}
源代碼如下所示:
/**
* Construct a new body with an appended value for the given parameter name.
*/
append(param: string, value: string): HttpParams;
檢查[這](https://stackoverflow.com/a/41133924/2545680) –
@Maximus只是嘗試,並沒有工作。 :/ –
我在回答中提供了一個示例,只是檢查了一下,它適用於我,我正在使用Angular v4.x –