代码之家  ›  专栏  ›  技术社区  ›  Patrick Dapa

不支持的媒体类型,Http错误415

  •  0
  • Patrick Dapa  · 技术社区  · 8 年前

    我实际上正在从事一个项目,该项目涉及一个Adobe Flash Player Windows和一些Flex,这些Flex调用spring mvc控制器中包含的rest服务,其目的是使用一个服务生成带有Jasper report的pdf文件。

    下面是调用web服务的ActionScript方法:

    private function editerCourrier():void{
    
    //Security.loadPolicyFile("http://appserv01.siege.xm:4040/Editions/RetardLivraison/crossdomain.xml");
    if(this.gridActivated == "mailing"){
        var request:URLRequest = new 
    
    URLRequest("http://10.102.22.143:8280/edition_sc_retards_livraisons/Export/RetardLivraisonLettre");
            var hdr:URLRequestHeader = new URLRequestHeader("Content-type", "application/json");
            request.method = URLRequestMethod.POST;
            request.requestHeaders.push(hdr);
            var jsonArray:Array = new Array();
            jsonArray.push({
                "civilite" : "Mr.",
                "destNom" : "TAMBE",
                "destPrenom" : "JOEL",
                "destAdresseFull" : "54 rue des Cocotiers",
                "destCP" : "93270",
                "destVille" : "ANTONY",
                "nomPays" : "FRANCE",
                "pjPath" : "http://192.168.200.97/intranet/e107_files/mail_attachement/MAIL_AVENANT_TEMPORAIRE_1507817106_1534679.txt"
            });
            request.data = jsonArray;
            navigateToURL(request,"win_cour");
        }
    }
    

    还有,这是rest控制器

    @Api
    @Controller
    public class RetardLivraisonLettreControllerImpl implements RetardLivraisonLettreController {
    
        private static Logger logger = Logger.getLogger(RetardLivraisonLettreControllerImpl.class);
    
        private final EditionConfig editionConfig;
    
        private final EditionService editionService;
    
        private static final String SUCCESS = "success";
    
        private static final String ERROR = "error";
    
        public RetardLivraisonLettreControllerImpl(EditionConfig editionConfig, EditionService editionService) {
            this.editionConfig = editionConfig;
            this.editionService = editionService;
        }
    
        @RequestMapping(value = "/Export/RetardLivraisonLettre", method = RequestMethod.POST, produces = "application/pdf", consumes = {
                "application/json",
                "application/x-www-form-urlencoded;charset=ISO-8859-1" }, headers = "Accept=application/x-www-form-urlencoded")
        @Override
        public ResponseEntity<String> retardLivraisonLettre(@RequestBody RetardLivraisonLettreBean bean,
                HttpServletResponse response) throws InvalidParameterException {
    
            logger.debug("appel retardLivraisonLettre");
    
            String nomCible = editionConfig.getNomCible();
    
            try {
                // Download du PDF
                logger.debug("Download du PDF");
    
                editionService.retardLivraisonLettre(bean, response.getOutputStream());
    
                response.setContentType("application/x-download");
                response.setHeader("Content-Disposition", "attachment; filename=" + nomCible);
                response.getWriter().close();
                response.setHeader(SUCCESS, "Edition du PDF de la lettre de retard de livraison effectué avec succès");
    
            } catch (IOException e) {
                logger.error(e.getMessage(), e);
                response.setHeader(ERROR, "Erreur lors de l'édition du PDF de la lettre de retard de livraison effectué");
                return new ResponseEntity<String>(response.getHeader(ERROR), HttpStatus.BAD_REQUEST);
            }
            return new ResponseEntity<String>(response.getHeader(SUCCESS), HttpStatus.ACCEPTED);
        }
    }
    
    1 回复  |  直到 8 年前
        1
  •  2
  •   Mario Varchmin SoftwareCreations    8 年前

    请求标头应命名为“内容类型”,而不是“内容类型”。