不支持 Spring/Postman 内容类型“application/octet-stream"不支持、类型、内容、Postman

由网友(落花殤☆傾城淚)分享简介:我正在使用 Postman 发送以下请求:I'm using Postman to send the following request:我的控制器如下所示:@RestController@RequestMapping(path = RestPath.CHALLENGE)public class Challen...

我正在使用 Postman 发送以下请求:

I'm using Postman to send the following request:

我的控制器如下所示:

@RestController
@RequestMapping(path = RestPath.CHALLENGE)
public class ChallengeController {

    private final ChallengeService<Challenge> service;

    @Autowired
    public ChallengeController(ChallengeService service) {
        this.service = service;
    }

    @ApiOperation(value = "Creates a new challenge in the system")
    @RequestMapping(method = RequestMethod.POST, consumes = {MediaType.MULTIPART_FORM_DATA_VALUE, MediaType.APPLICATION_OCTET_STREAM_VALUE},
        produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseStatus(HttpStatus.CREATED)
    public ChallengeDto create(@ApiParam(value = "The details of the challenge to create") @RequestPart("challengeCreate") @Valid @NotNull @NotBlank ChallengeCreateDto challengeCreate,
                           @ApiParam(value = "The challenge file") @RequestPart("file") @Valid @NotNull @NotBlank MultipartFile file) {
        return service.create(challengeCreate, file);
    }
}

我已经尝试将消耗"更改为将 APPLICATION_OCTET_STREAM_VALUE 删除为 MULTIPART_FORM_DATA_VALUE 并尝试将其删除,但这些都没有帮助.

I already tried to change the "consumes" to delete the APPLICATION_OCTET_STREAM_VALUE to MULTIPART_FORM_DATA_VALUE and also tried to delete it, but none of these helped.

如果您需要更多信息,请告诉我.谢谢.

Please tell me if you need more information. Thanks.

推荐答案

@Rokin 答案很好,但不需要将json放入文件并上传.您也可以通过将内容类型传递给 json 对象来实现.Postman 在发送表单数据时支持内容类型选项.进一步请参阅下面的自我描述图片.

@Rokin Answer is good but dont need to place json in file and upload. You can achieve by passing content type to json object as well. Postman support content type options while sending form-data. for further see the below image which is self descriptive.

阅读全文

相关推荐

最新文章