hutool的代理失败Unable to tunnel through proxy. Proxy returns “HTTP1.0 407 Proxy Authentication Required

springboot中代理失败,下面的此配置要在springboot启动之前设置System.setProperty("jdk.http.auth.tunneling.disabledSchemes&quo

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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信