【发布时间】:2019-12-28 19:55:27
【问题描述】:
- 我正在使用 Angular 框架,
- 我试图通过 FormData 向服务器发送数据
- 我正在分享我的代码
component.ts
const ProposalData: FormData = new FormData();
ProposalData.append('customerId', this.customerId);
ProposalData.append('file', this.file);
const token = localStorage.getItem('currentUser');
this.rest.newProposals(ProposalData , token).subscribe(
result => { console.log(result) }
);
service.ts
newProposals(value , token) {
let headers = new HttpHeaders();
headers = headers.append('Content-Type', 'application/json; charset=utf-8');
headers = headers.append('Authorization', token);
return this.http.post<any>(this.addProposals , value , {headers});
}
问题是
一旦我尝试通过 Post 方法将我的 formData 发送到服务器,我的数据在服务器上没有到达并且我的 FormData 在服务器上是空的 .
注意:当我 console.log formData 时,数据被控制台是正确的。但它不会以某种方式发送到服务器
【问题讨论】:
标签: angular angular6 angular5 angular-httpclient