httpClient4.5.3 代理设置账号

该博客介绍了如何在Java中使用httpClient4.5.3库设置代理服务器,包括指定代理主机地址、端口、用户名和密码。通过创建`CredentialsProvider`并设置`UsernamePasswordCredentials`,然后在`HttpClients.custom()`中配置,并利用`RequestConfig`定制请求参数,实现了带有代理的HTTP请求。
摘要由CSDN通过智能技术生成
public static void main(String[] args) {
		
		
		getHtml("http://news.qq.com",null);
	}
	
	public static CloseableHttpResponse getHtml(String url,String cookie) {

		CredentialsProvider credsProvider = new BasicCredentialsProvider();
		credsProvider.setCredentials(
		    new AuthScope("202.194.232.132",10010 ), 
		    new UsernamePasswordCredentials("qf", "qf3.1415"));
		
		CookieStore cookieStore = null;				
		CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).setDefaultCookieStore(cookieStore).build();

		
		HttpGet hp = new HttpGet(url);
        HttpHost proxy = new HttpHost("202.194.232.132", 10010);
        RequestConfig config = RequestConfig.custom()
        		.setSocketTimeout(10000).setConnectTimeout(10000).
				setProxy(proxy).build();
		
        CloseableHttpResponse response = null;
		System.out.println("开始  请求 !
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值