Angular9 post 使用 HttpClient 通过表单数据将数据 API

Angular9 post the data to API by form data with HttpClient

我正在使用 Angular9,我想通过使用 HttpClient

的表单数据 post 将数据 API
const headers = new HttpHeaders({
    'Content-type': 'application/x-www-form-urlencoded; charset=utf-8' 
});

let data: FormData = new FormData();
data.append('userName', this.loginData.userName); 
data.append('password', this.loginData.password);

this.http.post(url, data, {headers: headers});

请求会像这样:

但我的预期是这样的:

我该怎么做?

我会将代码更改为简单

this.http.post<any>(url, this.loginData);

注意事项:

  1. 为了安全起见,我已将 get 更改为 post
  2. 我已经使用 <any>
  3. any 的回复进行了类型转换
  4. 我已经删除了 headers,angular 会为我添加适当的 headers