Spring Boot OpenFeign 发送 form-url-encoded 表单数据

Spring Boot OpenFeign About 841 words

代码

注意:Map中的value泛型必须是?(即:Map<String, ?>),否则会带上modCounttable这些Map的字段。

@FeignClient(name = "my-feign-client", url = "${keycloak.auth-server-url}")
public interface TokenFeign {

    @PostMapping(value = "/realms/{realm}/protocol/openid-connect/token", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    @ResponseBody
    ResponseEntity<JsonNode> createToken(@PathVariable(value = "realm") String realm, Map<String, ?> params);

}

备注

用的spring-cloud-starter-openfeign版本是3.0.5,如果还是无法请求成功,可以添加一下配置

@Configuration
@RequiredArgsConstructor
public class FeignConfig {

    private final ObjectFactory<HttpMessageConverters> messageConverters;

    @Bean
    public Encoder encoder(ObjectFactory<HttpMessageConverters> converters) {
        return new SpringFormEncoder(new SpringEncoder(converters));
    }

}
Views: 1,037 · Posted: 2023-07-11

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh