Angular 文件下载错误:SyntaxError:JSON中的意外标记M位于位置0和11 HttpPost

Angular 文件下载错误:SyntaxError:JSON中的意外标记M位于位置0和11 HttpPost,angular,angular11,Angular,Angular11,我在下载angular 11中的文件时遇到上述错误。 状态代码为200 OK。Asp.Net Web Api用于发布文件 下面是代码 this.http.post<Blob>(url,{responseType: 'blob'}).subscribe({ next: versionfiledata=>{ return versionfiledata; }, error: error => { console.

我在下载angular 11中的文件时遇到上述错误。 状态代码为200 OK。Asp.Net Web Api用于发布文件

下面是代码

this.http.post<Blob>(url,{responseType: 'blob'}).subscribe({
    next: versionfiledata=>{
      return  versionfiledata;
    },
    error: error => {
      
      console.error('There was an error!', error);
    }
    
      } )
this.http.post(url,{responseType:'blob'})。订阅({
下一步:versionfiledata=>{
返回versionfidelata;
},
错误:错误=>{
console.error('发生错误!',error);
}
} )
错误:SyntaxError:JSON中位于位置0的意外标记M

不确定,但我尝试过使用响应类型作为blob,但仍然使用Angular 11得到错误

const headers={'responseType':'blob'作为'json'};
 const headers = { 'responseType': 'blob' as 'json'};
    const body = { title: 'Test' };
    return this.http.post<Blob>(url,body,headers).subscribe({next:response=>{
      console.log(response);
    var blob=new Blob([response],{type:"application/octet-stream"});
      FileSaver.saveAs(blob,file);

    }, error: error => {console.log("download error");}
  });
const body={title:'Test'}; 返回此.http.post(url、正文、标题).subscribe({next:response=>{ 控制台日志(响应); var blob=新blob([response],{type:“application/octet stream”}); FileSaver.saveAs(blob,file); },error:error=>{console.log(“下载错误”);} });

您需要更改标题中的响应。

尝试使用responseType:'blob'作为'json'而不是responseType:'blob'。参考-我仍然收到错误。当前的响应可能是html或EXE。这是相同的错误吗?错误:SyntaxError:JSON中位于位置0的意外标记M?您可以添加完整的错误日志吗?错误:SyntaxError:JSON中的意外标记M位于XMLHtt…的JSON.parse()位置0处,文本:“MZ”�谢谢