不支持 Spring/Postman 内容类型“application/octet-stream" [英] Spring/Postman Content type 'application/octet-stream' not supported

查看:28
本文介绍了不支持 Spring/Postman 内容类型“application/octet-stream"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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.

这篇关于不支持 Spring/Postman 内容类型“application/octet-stream"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆