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依赖
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.21</version>
</dependency>
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")
.setHttpProxy("代理的IP地址", 端口号)
.basicProxyAuth("账号", "密码")
.execute();
发布者:admin,转转请注明出处:http://www.yc00.com/web/1755027904a5228549.html
评论列表(0条)