不支持的媒体类型,HTTP 错误 415
Unsupported Media Type, Http error 415
我实际上正在做一个涉及 Adobe Flash Player Windows 和一些 Flex 的项目,这些 Flex 调用包含在 spring mvc 控制器中的休息服务,其目的是使用服务生成带有 Jasper 报告的 pdf 文件。
这是调用网络服务的 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");
}
}
此外,这里是其余的控制器
@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);
}
}
请求头应该命名为"Content-Type",而不是"Content-type"。
我实际上正在做一个涉及 Adobe Flash Player Windows 和一些 Flex 的项目,这些 Flex 调用包含在 spring mvc 控制器中的休息服务,其目的是使用服务生成带有 Jasper 报告的 pdf 文件。
这是调用网络服务的 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");
}
}
此外,这里是其余的控制器
@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);
}
}
请求头应该命名为"Content-Type",而不是"Content-type"。