springboot中代理失败,下面的此配置要在springboot启动之前设置

System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");

import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

@Configuration

public class JDKConfig {

@PostConstruct

public void httpsProxyConfig(){

System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");

}

}

使用

1、pom依赖

cn.hutool

hutool-all

5.7.21

2、实现

Authenticator.setDefault(

new Authenticator() {

@Override

public PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication("账号", "密码".toCharArray());

}

}

);

/**

* springboot中下面jdk配置要在启动前配置

*/

System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");

HttpResponse execute = HttpRequest.get("https://www.baidu.com")

.setHttpProxy("代理的IP地址", 端口号)

.basicProxyAuth("账号", "密码")

.execute();

推荐阅读

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: