当对方的接口参数是@RequestBody类型时如何调用。
1、对方controller接口写发如下:- @PostMapping(value = "/test")
- @ResponseBody
- public StringresultBack(@RequestBody String resultJson) {
- return "helloWorld";
- }
复制代码 2、Apipost的调用方式如下:
3、用java代码调用对方接口方法
(1)引入依赖- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- httpcore</artifactId>
- <version>4.4.10</version>
- </dependency>
-
- <dependency>
- <groupId>commons-httpclient</groupId>
- commons-httpclient</artifactId>
- <version>3.1</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- httpclient</artifactId>
- <version>4.5.6</version>
- </dependency>
复制代码 (2)调用方法
来源:豆瓜网用户自行投稿发布,如果侵权,请联系站长删除 |