首页 > 解决方案 > 表单应用程序编码值在弹簧休息时不起作用

问题描述

我有以下发布请求,其中以下是控制器代码

@RestController
@RequestMapping(/flow", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)

@Override
    @ResponseStatus(HttpStatus.OK)
    @PostMapping("{abcCode}/token")
    public TokenResponse createToken(@PathVariable("abcCode") String abcCode,
            @RequestParam("grant_type") String grantType,
            @RequestParam String code,
            @RequestParam("redirect_uri") String redirectUri,
            @RequestParam String clientId) {
        LOG.info(
                "Received call for createIdToken for abcCode: {} , clientId: {} , grantType:  {} ,code: {} , redirectUri: {}",
                abcCode, clientId, grantType, code, redirectUri);


                }

现在的问题是,当我通过邮递员通过选择正文类型作为应用程序表单编码来测试相同的上述控制器时,它工作正常但是当我在邮递员中选择正文类型为无并且只是将上述请求参数作为查询一传递那么它也可以工作,理想情况下它不应该请告知我如何克服同样的问题

http://localhost:19080/testService/flow/token?grant_type=authorization_code&code=3272&redirect_uri=http://www.abchui.com&clientId=ATS

它不适用于上述网址

标签: javaspringrest

解决方案


来自弹簧来源:

public static final String APPLICATION_FORM_URLENCODED_VALUE = "application/x-www-form-urlencoded";

根据 docs,当使用 url-form-encoded 数据作为查询参数传递时。尝试更改表单 mime 类型。


推荐阅读