调整请求标头以被Spring Boot资源接受

时间:2019-02-09 14:28:28

标签: java spring-boot request multipartform-data

我的Spring Boot Resource没有收到我的请求。 这是资源定义:

@PostMapping(name = "sign_one_doc", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public ResponseEntity<InputStreamResource> signDocument(
            @RequestParam("file") MultipartFile data,
            @RequestPart("isTimestamping") boolean isTimestamping,
            @RequestPart("isMakeCheck") boolean isMakeCheck,
            @RequestPart("signMode") int signMode,
            @RequestPart("certClientID") int certClientID,
            @RequestPart("isCertLocal") boolean isCertLocal
    ) throws IOException, DocSignException, InputStreamReadException {
        RequestData requestData
                = signCtrl.signFile(data.getInputStream(), data.getOriginalFilename(), signMode, certClientID, isTimestamping, isMakeCheck, isCertLocal);

        HttpHeaders headers = new HttpHeaders();
        InputStreamResource inputStreamResource = new InputStreamResource(requestData.currentCtxFile());
        headers.setContentLength(requestData.currentCtxFileBA().length);
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
    }
我发送的(通过失眠)的

请求设置了content-type: multipart/form-dataaccept: application/octet-stream enter image description here

但是当我发送此请求时,弹簧只说:

 Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/octet-stream' not supported]
 Resolved [org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation]

我设置错了什么,为什么?另外,您是否会如此友善并提供此资源的curl请求?

我尝试过: curl -v --include -F isTimestamping=false -F file=@test.pdf -H 'Content-Type: multipart/form-data' http://localhost:8080/sign_one_doc

但是spring失败了:

java.io.EOFException: Unexpected EOF read on the socket

男人,很难发送请求,所有可能的事情都失败了:D

1 个答案:

答案 0 :(得分:0)

我需要将@RequestPart更改为@RequestParam。 卷曲问题仍未解决