无标题在feign post中,如何发送 form-url-encoded 数据
Posted 大树叶
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无标题在feign post中,如何发送 form-url-encoded 数据相关的知识,希望对你有一定的参考价值。
参考文章:
https://stackoverflow.com/questions/35803093/how-to-post-form-url-encoded-data-with-spring-cloud-feign
1:首先加一个配置文件 CoreFeignConfiguration,如下
package xxxx;
import feign.codec.Encoder;
import feign.form.FormEncoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope;
import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;
public class CoreFeignConfiguration
@Autowired
private ObjectFactory messageConverters;
@Bean
@Primary
@Scope(SCOPE_PROTOTYPE)
Encoder feignFormEncoder()
return new FormEncoder(new SpringEncoder(this.messageConverters));
你的feign client 像如下的东西
@FeignClient(
name = “eca-api”,
url = “$url.feign.eca-api”,
configuration = CoreFeignConfiguration.class,
fallbackFactory = EcaApiClientFallbackFactory.class
)
public interface EcaApiClient
@RequestMapping(value = “/open-api/token”, method = POST,
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
@Headers(“Content-Type: application/x-www-form-urlencoded”)
ECAR getToken(@RequestHeader(name = “Authorization”) String secret,
Map<String, ?> formParams);
以上是关于无标题在feign post中,如何发送 form-url-encoded 数据的主要内容,如果未能解决你的问题,请参考以下文章
无标题在feign post中,如何发送 form-url-encoded 数据
如何在 webclient 的 post 请求中发送 x-www-form-urlencoded? [复制]
在android中使用Http Post发送Form-data Post请求
如何使用附加的@RequestBody 在 POST 请求中将 Pageable 传递给 Feign 客户端