企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 组件源码 /** * <b>方法描述:</b> 服务调用(ip-port) <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2020-07-09 16:18:53 <br/> * * @param url 入参|接口地址|{@link java.lang.String} * @param json 入参|参数|{@link java.lang.String} * @param outPara 出参|Rest接口返回参数|{@link java.lang.String} * @return 0 失败<br/> * 1 成功<br/> */ @Component(label = "服务调用(ip-port)", style = "判断型", type = "同步组件", comment = "调用HTTP接口,通过使用IP+端口 全路径的URL地址,例:http://192.168.1.53:1110/bus/test。使用json格式。仅限于post请求", version = "1.0.0", deprecated = false, author = "admin", date = "2020-07-09 04:18:53") @InParams(param = { @Param(name = "url", comment = "接口地址", type = java.lang.String.class), @Param(name = "json", comment = "参数", type = java.lang.String.class) }) @OutParams(param = { @Param(name = "outPara", comment = "Rest接口返回参数", type = java.lang.String.class) }) @Returns(returns = { @Return(id = "0", desp = "失败"), @Return(id = "1", desp = "成功") }) public static ResultBase P_doPostJson(String url, String json) { CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpResponse response = null; String resultString = ""; try { HttpPost httpPost = new HttpPost(url); StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON); httpPost.setEntity(entity); AppLog.info("执行 http请求,url={},params={}", url, json); response = httpClient.execute(httpPost); resultString = EntityUtils.toString(response.getEntity(), "utf-8"); AppLog.info("http 请求返回参数={}", resultString); } catch (Exception e) { AppLog.error(e.getMessage(), e); return ResultBase.newFailureResult("TPTK0023", "调用第三方接口异常:" + AppLog.errorMsg(e)); } finally { try { response.close(); } catch (IOException e) { AppLog.error(e); } } return ResultBase.newSuccessResult(resultString); } # 交易中组件使用方式 ![](https://img.kancloud.cn/7d/f4/7df41f801903cf91fe263eb0809573b1_1188x750.jpg) # 参数说明及示例 ## 入口参数 接口地址:其他服务的接口地址,填写ip:端口等方式,示例: `"http://192.168.1.53:1110/bus/test"` 参数:接口请求参数,传入json字符串,示例: `"{\"sex\":\"男\",\"add\":\"重庆\"}"` ## 出口参数 Rest接口返回参数:调用接口返回结果,示例: `__INNER__["result"]` > 调用HTTP接口,通过使用IP+端口 全路径的URL地址,例:`http://192.168.1.53:1110/bus/test`。使用json格式。仅限于post请求