春季休息将不接受多部分内容类型 Apache Tomcat / 7.0.42

使用Http-Client 4.x的客户端代码:

        multipartentityBuilder builder = multipartentityBuilder.create();
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        FileBody fileBody = new FileBody(file,ContentType.MULTIPART_FORM_DATA);
        builder.addPart("files",fileBody);
        builder.addPart("data",new StringBody(data,ContentType.APPLICATION_JSON));
        HttpEntity entity = builder.build();
            httpPost.setEntity(entity);

        requestObject = httpPost;
        if (requestObject != null) {
            setHeaders(requestObject);
            try {
                HttpResponse response = null;

                _log.info("[invokeHttpMethod] request.URI=" + requestObject.geturi().toASCIIString() + ",Method=" + requestObject.getMethod() + ",Authorization="
                        + requestObject.getFirstHeader(Iconstant.AUTHORIZATION)+ ",Content Type: " +requestObject.getFirstHeader(Iconstant.CONTENT_TYPE));

                response = httpClient.execute(requestObject);

服务器代码:

@RequestMapping(值=“ / notification / file”,方法= RequestMethod.POST,消耗= MediaType.MULTIPART_FORM_DATA_VALUE,标头=“ accept = application / xml,application / json”)     公共@ResponseBody ResponseEntity processnotificationFile(

        @RequestHeader(value = "Authorization",required = true) String authorization,@RequestBody(required = true) NotificationRequest notificationRequest,@RequestParam("files") MultipartFile multiPart[]) {

    _log.info("[processnotificationFile] Started.."+ multiPart);
    ResponseEntity<Object> responseEntity = null;
    try {
        //notificationEngineservice.processnotification(notificationRequest);
    } catch (Exception e) {
        e.printStackTrace();
    }
    responseEntity = new ResponseEntity<Object>(HttpStatus.OK);
    return responseEntity;
}

错误: HTTP状态415-

类型状态报告

消息

描述服务器拒绝了此请求,因为请求实体的格式不受请求方法的请求资源所支持。

Apache Tomcat / 7.0.42

即使我在服务器控制器剩余端点中添加了多部分功能,但仍然遇到相同的问题

liudongmei2006407114 回答:春季休息将不接受多部分内容类型 Apache Tomcat / 7.0.42

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2900391.html

大家都在问