Java

jdk 1.8
httpclient 4.4.1
httpcore 4.4.1
httpclientutil
1
2
3
4
代码

import org.apache.commons.codec.binary.Base64;
import org.apache.http.Header;

import com.arronlong.httpclientutil.HttpClientUtil;
import com.arronlong.httpclientutil.common.HttpConfig;
import com.arronlong.httpclientutil.common.HttpHeader;
import com.arronlong.httpclientutil.exception.HttpProcessException;
public class UrlTest {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    String result1 = null;
    String url = "http://192.168.1.151:8080/api/v1/clusters/test/services/FLUME/components/FLUME_HANDLER?fields=metrics";
    String authInfo = "admin:admin";//这里填入"用户名:密码"
    byte[] tokenByte = Base64.encodeBase64(authInfo.getBytes());

    String token ="Basic " + new String(tokenByte);

    Header[] headers = HttpHeader.custom().authorization(token).build();
    HttpConfig config = HttpConfig.custom().headers(headers).url(url).encoding("utf-8");
    try{
        result1 = HttpClientUtil.get(config);
        System.out.println(result1);
    } catch (HttpProcessException e){
    System.out.println("访问ADM接口失败!");
    e.printStackTrace();
    }//get请求
}

}

作者:井口者
来源:CSDN
原文:https://blog.csdn.net/qiu265843468/article/details/78872749
版权声明:本文为博主原创文章,转载请附上博文链接!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值