`
张玉龙
  • 浏览: 737186 次
  • 性别: Icon_minigender_1
  • 来自: 沈阳
社区版块
存档分类
最新评论

设置代理

 
阅读更多
  // 设置代理的密码验证 
                Authenticator auth = new Authenticator() { 
                    private PasswordAuthentication pa =  
                        new PasswordAuthentication("username", "pwd".toCharArray()); 
                   
                    protected PasswordAuthentication getPasswordAuthentication() { 
                        return pa; 
                    } 
                }; 
                Authenticator.setDefault(auth); 
               
                Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.baidu.com", 8080));
               
                URL urlAddress = new URL(url);
               
                urlAddress.openConnection(proxy)


DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(
    new AuthScope("PROXY HOST", 8080),
    new UsernamePasswordCredentials("username", "password"));

HttpHost targetHost = new HttpHost("TARGET HOST", 443, "https");
HttpHost proxy = new HttpHost("PROXY HOST", 8080);

httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics