无法将formData发送到服务器

问题描述 投票:0回答:1
  • 我正在使用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框架,在这里我试图通过FormData将数据发送到服务器,我正在共享我的代码组件。tsconst ProposalData:FormData = new FormData(); ProposalData.append('...

angular angular6 angular5 angular-httpclient
1个回答
0
投票

您可以在component.ts中尝试这样

© www.soinside.com 2019 - 2024. All rights reserved.