Angular 如何通过英语中的POST请求将CSV文件发送到spring应用程序?

Angular 如何通过英语中的POST请求将CSV文件发送到spring应用程序?,angular,spring,spring-boot,rest,Angular,Spring,Spring Boot,Rest,在后端控制台中,我收到此错误“不支持内容类型'application/json'”。我需要上传并发送CSV,因为它是从POST请求到后端。我是盎格鲁语的新手。您可能需要更改此部分 @ViewChild('fileImportInput') fileImportInput: any; fileChangeListener($event: any): void { const files = $event.srcElement.files; const studentsFil

在后端控制台中,我收到此错误“不支持内容类型'application/json'”。我需要上传并发送CSV,因为它是从POST请求到后端。我是盎格鲁语的新手。

您可能需要更改此部分

@ViewChild('fileImportInput') fileImportInput: any;

  fileChangeListener($event: any): void {

    const files = $event.srcElement.files;
    const studentsFile = files[0];
    let formData:FormData = new FormData();
    formData.append('studentsFile', studentsFile, studentsFile.name);
    
    this.http.post('/api/enroll', { params: { batchId: `${this.batchId}`},  formData}).subscribe(response => {
      console.log(response);
    });

致:

formData
是请求主体,是post函数的第二个参数。第三个参数是选项。

您也可以共享“spring boot”接收端吗?
this.http.post('/api/enroll', { params: { batchId: `${this.batchId}`},  formData}).subscribe(response => {
  console.log(response);
});
this.http.post('/api/enroll', formData, { params: { batchId: `${this.batchId}`}}).subscribe(response => {
  console.log(response);
});