Kinbana监控数据获取 Jsoup 发送 Post请求 RequestBody 为 Json格式

	public String clusterJson() {
		String result = null;
		try {
			String str = Jsoup.connect("http://192.168.3.186/api/monitoring/v1/clusters")
					.userAgent("Mozilla/5.0").timeout(10 * 1000).method(Method.POST)
					.header("Content-Type", "application/json")
					.header("kbn-name", "kibana")   //Kinbana有header检测,需要包含此项
					.header("kbn-version", "5.6.3")
					.data("a", "b")  // 如果不加 data,requestBody 不会当json格式处理 而是默认格式
					.requestBody("{\"timeRange\":{\"min\":\"2018-01-15T07:05:37.504Z\",\"max\":\"2018-01-15T08:05:37.505Z\"}}").followRedirects(true).ignoreContentType(true)
					.execute().body();
			result = str.substring(1, str.length() - 1); //去除首尾的[] 
		} catch (IOException ioe) {
			logger.error("MonitorElasticSearch clusterJson() post Es 获取clusters json 失败", ioe);
		}
		return result;
	}

     示例为发送post请求 从Kinbana获取clusters json格式信息

     注意jsoup版本至少1.9.1 否则不包含requestBody方法

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值