Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试以Angular方式上载文件时出错(内容处置)_Angular_Typescript - Fatal编程技术网

尝试以Angular方式上载文件时出错(内容处置)

尝试以Angular方式上载文件时出错(内容处置),angular,typescript,Angular,Typescript,我正试图上传一个带有angular的文件,当我提交请愿书时,它出错了。它说请求已被CORS策略阻止:飞行前响应中的访问控制允许标头不允许请求标头字段内容处置 这是我的代码: postXml(serviceName: string, data:any = {}){ const url = environment.apiUrl + "/" + serviceName; let token = this.storageService.getWithoutAsyn

我正试图上传一个带有angular的文件,当我提交请愿书时,它出错了。它说请求已被CORS策略阻止:飞行前响应中的访问控制允许标头不允许请求标头字段内容处置

这是我的代码:

  postXml(serviceName: string, data:any = {}){
    const url = environment.apiUrl + "/" + serviceName;
    let token = this.storageService.getWithoutAsync(AuthConstants.AUTH);
    const header = new HttpHeaders({
      'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
      'Authorization': `${token}`,
      'Content-Disposition':"attachment; filename='file.xls'"
    });
    return this.http.post(url, data, { headers: header})
  }

该错误是因为您正在对与页面所在域不同的域执行HttpRequest。因此,浏览器正在阻止它,因为出于安全原因,它通常允许同一来源的请求。您需要从API中允许多个域可以调用此API。你可以找到一些帮助

您可以检查此项以便更好地理解