Springfox swagger-ui 不发送内容类型标头 [英] Springfox swagger-ui not sending with content-type header

查看:48
本文介绍了Springfox swagger-ui 不发送内容类型标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 SpringFox 构建将 swagger 集成到我的 Spring Boot 项目中,它适用于我的 GET API.但是,在需要 application/json 格式的请求的 POST API 上,swagger-ui 没有设置标头.

我的代码:

@PostMapping(value="/login",consume="application/json", products="application/json")公共 WsResponse 登录(UserLoginRequest requestBody)抛出异常 {validateAuthToken(requestBody.getId(), requestBody.getToken());返回 serviceWs.login(requestBody);}

从 swagger-ui 生成的命令:

curl -X POST "http://localhost:8080/api/login?token=2342343324&username=23434&password=123" -H "accept: application/json"

请注意,未设置标头Content-Type",因此后端在尝试调用时会出错.

问题类似于

注意:适用于 springfox-swagger2 和 springfox-swagger-ui v2.8.0

I have integrated swagger to my Spring Boot project using SpringFox build and it work for my GET API. However on my POST API which requires the request in application/json format, the swagger-ui doesn't set the header.

My Code:

@PostMapping(value="/login", consumes="application/json", produces="application/json")
    public WsResponse login(UserLoginRequest requestBody) throws Exception {

        validateAuthToken(requestBody.getId(), requestBody.getToken());

        return serviceWs.login(requestBody);
    }

The command generated from swagger-ui:

curl -X POST "http://localhost:8080/api/login?token=2342343324&username=23434&password=123" -H "accept: application/json"

Note that the header "Content-Type" is not set and thus backend is giving an error when trying to call.

The issue is similar to this post but there's no resolution, any help is appreciated.

解决方案

Try putting application/json within the braces:

Note: Works for me for springfox-swagger2 and springfox-swagger-ui v2.8.0

这篇关于Springfox swagger-ui 不发送内容类型标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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