이전에 저자는 "Spring Cloud Feign을 사용하여 파일 업로드"를 썼습니다. 최근에 동료는 레거시 스트럿 골동품 시스템과 연결하고 있으며 Feign을 사용하여 양식 제출을 구현해야합니다. 실제로 단계는 비슷합니다. 이 기사에 첨부 된 단계는 이전 기사에 추가 된 것으로 간주됩니다.
종속성 추가 :
<pectionency> <groupid> io.github.openfeign.form </groupid> <artifactid> feign-form </artifactid> <bersion> 3.2.2 </version> </dependency> <prectionency> <groupId> io.github.openfeign.form </groupIdid> feign-form-spring </artifactid> <버전> 3.2.2 </버전> </의존성>
Feign 클라이언트 예 :
@feignclient (name = "xxx", url = "http://www.itmuch.com/", configuration = testfeignclient.formsupportconfig.class) public interface testfeignclient {@postmapping (value = "/test", consumer = {mediatype.application_form_urled_uded_value}, {mediaType.application_json_utf8_value}) void post (map <string,?> QueryParam); class formsupportconfig {@autowired private objectfactory <httpmessageconverters> messageconverters; // 양식 제출을 지원하는 새로운 양식 인코더 @bean public encoder feignformencoder () {return new springencoder (new springencoder (messageconverters)); } // feign의 log @bean public logger.level logger () {return logger.level.full; }}}Call example:
@getMapping ( "/user/{id}") public user findById (@PathVariable long id) {hashmap <string, string> param = maps.newhashmap (); param.put ( "사용자 이름", "Zhangsan"); param.put ( "비밀번호", "pwd"); this.testfeignclient.post (param); 새로운 사용자 ()를 반환합니다 ();}통나무:
... [testfeignclient#post] ---> post http://www.baidu.com/test http/1.1
... [TestFeignClient#post] 수락 : application/json; charset = utf-8
... [TestFeignClient#post] Content-Type : Application/x-www-form-urlencoded; charset = utf-8
... [TestFeignClient#post] 컨텐츠 길이 : 30
... [TestFeignClient#post]
... [testFeignClient#post] password = pwd & username = zhangsan
... [testfeignclient#post] ---> end http (30 바이트 바디)
로그에서 Feign이 양식을 사용하여 현재 데이터를 제출할 수 있음을 알 수 있습니다.
참조 문서
https://github.com/openfeign/feign-form
https://stackoverflow.com/questions/35803093/how-to-post-fort-url-encoded-data-with-spring-cloud-feign
위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.