JAVA代理访问https带账号密码

HttpHost proxy = new HttpHost(ip, port, "http");
CredentialsProvider provider = new BasicCredentialsProvider();
provider.setCredentials(new AuthScope(proxy), new UsernamePasswordCredentials(账号, 密码));
CloseableHttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(provider).build();
RequestConfig requestConfig = RequestConfig.custom().setProxy(proxy).build();
CloseableHttpResponse response = null;
HttpGet get = new HttpGet(href);
get.setConfig(requestConfig);
response = httpClient.execute(get);

InputStream inputStream = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
StringBuffer bs = new StringBuffer();
String line;
while ((line = reader.readLine()) != null) {
    bs.append(line);
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java中使用Selenium和Firefox浏览器进行代理设置,可以按照以下步骤进行: 1. 下载Firefox浏览器,并安装FoxyProxy Standard插件。 2. 配置FoxyProxy,添加代理服务器地址和端口号,并选择“HTTP代理”类型。 3. 在FoxyProxy的“身份验证”选项卡中,填写代理服务器的用户名密码,保存设置。 4. 在Java中使用Selenium启动Firefox浏览器,并使用FirefoxProfile设置代理服务器。 5. 在Firefox浏览器中访问需要使用代理服务器的网站,即可自动使用设置好的代理服务器进行访问。 下面是一个示例代码: ``` import org.openqa.selenium.Proxy; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; // 创建FirefoxProfile对象 FirefoxProfile firefoxProfile = new FirefoxProfile(); // 设置代理服务器地址和端口号 String proxyUrl = "http://proxy.server.com:port"; firefoxProfile.setPreference("network.proxy.type", 1); firefoxProfile.setPreference("network.proxy.http", proxyUrl); firefoxProfile.setPreference("network.proxy.http_port", 80); // 设置代理服务器的用户名密码 String proxyUsername = "username"; String proxyPassword = "password"; firefoxProfile.setPreference("extensions.foxyproxy.proxyPassword", proxyPassword); firefoxProfile.setPreference("extensions.foxyproxy.proxyUsername", proxyUsername); // 启动Firefox浏览器 DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability(CapabilityType.PROXY, new Proxy().setHttpProxy(proxyUrl)); WebDriver driver = new FirefoxDriver(capabilities); // 访问需要使用代理服务器的网站 driver.get("https://www.example.com"); ``` 通过以上代码,就可以在Java中使用Selenium和Firefox浏览器进行代理设置。注意,这里使用了FoxyProxy插件设置了代理服务器的账号密码,且在Java代码中设置了FirefoxProfile和DesiredCapabilities,来启动Firefox浏览器并设置代理服务器。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值