zoukankan      html  css  js  c++  java
  • 使用HttpClient4调用rabbitmq rest api代码示例

    package com.gsafety.rabbitmq.api;

    import org.apache.http.HttpEntity;
    import org.apache.http.HttpHost;
    import org.apache.http.HttpResponse;
    import org.apache.http.auth.AuthScope;
    import org.apache.http.auth.UsernamePasswordCredentials;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.impl.client.BasicCredentialsProvider;
    import org.apache.http.impl.client.CloseableHttpClient;
    import org.apache.http.impl.client.HttpClients;
    import org.apache.http.util.EntityUtils;

    import java.io.IOException;

    /**
    * Created by user on 2017/6/8.
    */
    public class RabbitRestTool {

    public static void main(String[] args) throws IOException {
    HttpHost host = new HttpHost("localhost", 15672);
        HttpGet httpGet = new HttpGet("/api/connections");
        //认证
         BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
         credentialsProvider.setCredentials(new AuthScope("localhost",15672),new UsernamePasswordCredentials("guest","guest"));
        CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();

        HttpResponse response = client.execute(host, httpGet);

         HttpEntity entity = response.getEntity();
         String s = EntityUtils.toString(entity);
         System.out.println(s);
    }
    }
  • 相关阅读:
    Docker安装
    Mysql 安全登陆工具 mysql_config_editor
    位图索引对于DML操作的影响
    删除Oracle Online Redo 测试
    16 Managing Undo
    Linux 不杀进程的情况下,如何释放磁盘资源
    SFTP 服务搭建
    8. DBNEWID 工具(使用nid命令修改db name及dbid)
    Null 值对索引排序的影响案例一则
    opensshd 源码升级
  • 原文地址:https://www.cnblogs.com/huangll99/p/6963221.html
Copyright © 2011-2022 走看看