以前は、著者は「Spring Cloud Feignを使用してファイルをアップロードする」と書いていました。最近、同僚がレガシーストラットアンティークシステムとつながり、フォームの提出を実装するためにfeignを使用する必要があります。実際、手順は似ています。この記事に添付された手順は、前の記事への追加と見なされます。
依存関係を追加:
<Dependency> <groupId> io.github.openfeign.form </groupid> <artifactid> feign-form </artifactid> <version> 3.2.2 </version> </dependency> <sependency> <shiplency> <groupid> io.github.openfeign.form </groupid> <artifactid> </artifactid> <バージョン> 3.2.2 </version> </dependency>
装うクライアントの例:
@feignclient(name = "xxx"、url = "http://www.itmuch.com/"、configuration = testfeignclient.formsupportconfig.class)public interface testfeignclient {@postmapping(value = "/test"、cunsumer = {mediatype.application_frulice.appliced_formextipe.applice {mediatype.application_json_utf8_value})void post(map <string、?> queryparam); class formsupportconfig {@autowired private objectFactory <httpmessageconverters> messageConverters; //フォームフォームsubmission @bean public encoder feignformencoder()をサポートするフォームエンコーダー{return new SpringFormenCoder(new SpringEncoder(MessageConverters)); } // feignのlog @bean public logger.level logger(){return logger.level.full; }}}コール例:
@getMapping( "/user/{id}")パブリックユーザーfindbyid(@pathvariable long id){hashmap <string、string> param = maps.newhashmap(); param.put( "username"、 "zhangsan"); param.put( "password"、 "pwd"); this.testfeignclient.post(param);新しいユーザーを返します();}ログ:
... [testfeignclient#post] ---> post http://www.baidu.com/test http/1.1
... [testfeignclient#post] Accept:application/json; charset = utf-8
... [testfeignclient#post] content-type:application/x-www-form-urlencoded; charset = utf-8
... [testfeignclient#post] Content-Length:30
... [testfeignclient#post]
... [testFeignClient#投稿]パスワード= PWD&USERNAME = Zhangsan
... [testfeignclient#post] ---> end http(30バイトボディ)
ログから、Feignはフォームフォームを使用して現時点でデータを送信できることがわかります。
参照ドキュメント
https://github.com/openfeign/feign-form
https://stackoverflow.com/questions/35803093/how-to-post-form-url-encoded-with-spring-cloud-feign
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。