http請求發送請求我需要發送用戶名和密碼到登錄api使用角度http post請求。這裏是我的代碼:我如何傳遞用戶名和密碼在角度4
const params = new URLSearchParams();
params.set('username', username);
params.set('password', password);
this.headers = new Headers({ 'content-type': 'application/x-www-form-urlencoded', 'authorization': 'Basic' });
this.options = new RequestOptions({headers: this.headers, method: RequestMethod.Post, params: params });
return this.http.post(this.config.baseUrlAuthSvc + this.config.login, this.options)
.map((response) => { return response; })
我收到以下錯誤響應:
請求URL:http://111.22.333.44:55/api/token 請求方法:OPTIONS 狀態代碼:400錯誤的請求 遠程地址:172.31.131.13 :85 推薦人政策:no-referrer-when-downgrade
我是否錯過了什麼?
您可能需要將請求主體設置爲'username = enteredUsername&password = enteredPassword' –
@jason是的,這就是我所做的。 params應該用於獲得請求 – Maverik