admin管理员组

文章数量:1567012

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();

本文标签: proxytunnelhutoolunable