mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add PassAuth
This commit is contained in:
@@ -1094,9 +1094,9 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用转发,如果需要转发返回转发结果,否则返回<code>null</code>
|
||||
* 调用转发,如果需要转发返回转发结果,否则返回{@code null}
|
||||
*
|
||||
* @return {@link HttpResponse},无转发返回 <code>null</code>
|
||||
* @return {@link HttpResponse},无转发返回 {@code null}
|
||||
*/
|
||||
private HttpResponse sendRedirectIfPossible() {
|
||||
if (this.maxRedirectCount < 1) {
|
||||
|
@@ -4,14 +4,13 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.date.TimeInterval;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.http.ssl.SSLSocketFactoryBuilder;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.Authenticator;
|
||||
import java.net.PasswordAuthentication;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -144,4 +143,25 @@ public class HttpRequestTest {
|
||||
Console.log(execute.body());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getByProxy(){
|
||||
System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
|
||||
|
||||
// 用户名密码, 若已添加白名单则不需要添加
|
||||
final String ProxyUser = "t10757311156848";
|
||||
final String ProxyPass = "ikm5uu44";
|
||||
|
||||
Authenticator.setDefault(new Authenticator() {
|
||||
public PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(ProxyUser, ProxyPass.toCharArray());
|
||||
}
|
||||
});
|
||||
|
||||
final HttpResponse res = HttpRequest.get("https://httpbin.org/get")
|
||||
.basicAuth(ProxyUser, ProxyPass)
|
||||
.setHttpProxy("tps193.kdlapi.com", 15818).execute();
|
||||
|
||||
Console.log(res.body());
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user