请购单失败

问题描述 投票:0回答:1

我正在尝试发出POST请求,将文件转换并下载为pdf,但是出现此错误:documento.service.ts:

  download(documento: IDocumento) {
    return this.http.post(SERVER_API_URL + "api/download/", documento).subscribe((response) => {
      saveAs(response, documento.tituloDocumento + "." + "pdf");
    });
  }

DocumentResource

    @RequestMapping(value = "/download", method = RequestMethod.POST)
public void download(HttpServletResponse response, @RequestBody DocumentoDTO documentoDTO) throws IOException {
    File file = new File(documentoDTO.getPathorigdoc());
    response.setContentType("pdf");
    response.setHeader("Content-disposition", "attachment;" + documentoDTO.getTituloDocumento());
    response.getOutputStream().write(Files.readAllBytes(file.toPath()));
}

Access to XMLHttpRequest at 'https://autenticacao.campogrande.ms.gov.br/auth/realms/dev/protocol/openid-connect/auth?response_type=code&client_id=web_app&scope=openid%20offline_access%20profile%20email%20address%20phone%20roles%20web-origins%20jhipster&state=DooRYbdfmKCip2apn-NOTWQOqWBGkeh-AigMtoJVfcM%3D&redirect_uri=http://localhost:9000/login/oauth2/code/oidc' (redirected from 'http://localhost:9000/api/download/') from origin 'http://localhost:9000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
autenticacao.campogrande.ms.gov.br/auth/realms/dev/protocol/openid-connect/auth?response_type=code&client_id=web_app&scope=openid%20offline_access%20profile%20email%20address%20phone%20roles%20web-origins%20jhipster&state=DooRYbdfmKCip2apn-NOTWQOqWBGkeh-AigMtoJVfcM%3D&redirect_uri=http://localhost:9000/login/oauth2/code/oidc:1 Failed to load resource: net::ERR_FAILED
webpack-internal:///./node_modules/@angular/core/fesm5/core.js:6249 ERROR HttpErrorResponse
angular spring spring-boot post request
1个回答
0
投票

我不知道您使用的是什么服务器,但是您需要修改服务中的标头值(以Java为例)

How to handle CORS using JAX-RS with Jersey

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