HttpClient携带请求JSON数据访问HTTP接口得到响应JSON数据详解编程语言
2023-06-13 09:11:51 时间
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
@RequestMapping(value = "/rabbit")
public class BpmToRabbitController {
private static final String RABBIT_API_URL = "http://localhost:8082/api/rfc/json";
@RequestMapping(value = "/api")
public Map String, Object visitRabbitApi(@RequestBody Map String, Object requestMap) throws Exception {
CloseableHttpClient client = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(RABBIT_API_URL);
String requestJson = JSON.toJSONString(requestMap);
StringEntity stringEntity = new StringEntity(requestJson);
stringEntity.setContentEncoding("UTF-8");
stringEntity.setContentType("application/json");
httpPost.setEntity(stringEntity);
CloseableHttpResponse httpResponse = client.execute(httpPost);
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
String responseJson = EntityUtils.toString(httpResponse.getEntity());
Map String, Object responseMap = JSON.parseObject(responseJson);
return responseMap;
return null;
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/19595.html
cjavaxml相关文章
- 利用单细胞技术和深度学习预测药物响应
- 响应式架构,也许只是杯有毒的美酒(上)
- java logbook_SpringBoot使用Logbook记录HTTP请求响应日志
- zblog响应式极简图片灯箱插件viewimglee,不足1kb的ViewImage.js超效率
- Vue响应式系统中的Watcher和Dep的关系-面试进阶
- vue2双向绑定原理:深入响应式原理defineProperty、watcher、get、set
- (一)virtual DOM 和 响应基础:proxy
- 如何使用SysRq组合键修复无响应的Linux系统
- Collect-MemoryDump:一款针对Windows的数字取证与事件应急响应工具
- 开心档-软件开发入门之Vue.js 响应接口
- SQLServer 错误 10060 在建立与服务器的连接时出错。 在连接到 SQL Server 时,在默认的设置下 SQL Server 不允许远程连接可能会导致此失败。 (提供程序:TCP 提供程序,错误:0 – 由于被连接方在一段时间后未正确响应,或者连接的主机无法响应,连接尝试失败。)(Microsoft SQL Server,错误:10060) 故障 处理 修复 支持远程
- 速度Linux操作系统键盘响应速度提升之旅(linux键盘响应)
- 安徽:开启“两线作战”模式,防汛应急响应升至I级
- Reactive(响应式)编程-Reactor
- 器 SQL Server表触发器:实现自动响应的利器(sqlserver表触发)
- MySQL无法响应:探索停止命令的奥秘(mysql 停止命令)
- 红色之火零延迟的Redis高可用架构(redis高可用无响应)