远程调用是为在java业务处理过程中,在后台调用其他项目api的工具。
1、在pom.xml注入依赖。
<dependency>
<groupId>org.jodd</groupId>
<artifactId>jodd-http</artifactId>
<version>3.6.6</version>
</dependency>
<dependency>
<groupId>org.jodd</groupId>
<artifactId>jodd-json</artifactId>
<version>3.6.6</version>
</dependency>
<dependency>
<groupId>org.jodd</groupId>
<artifactId>jodd-bean</artifactId>
<version>3.6.6</version>
</dependency>
2、在java代码中调用
//api路径 String requestUrl="api"; //请求参数 Map<String,String> map=new HashMap<>(); //get请求 HttpResponse response = HttpRequest.get(requestUrl) .basicAuthentication("账号","密码")//需要账号、密码验证时,需要放入 .query(map) .send(); //post请求
HttpResponse response = HttpRequest.post(requestUrl) .basicAuthentication("账号","密码")//需要账号、密码验证时,需要放入 .query(map) .send();if (response.statusCode() == 200) { String responseBody = rsp.charset("utf-8").bodyText(); }