照着官网的 demo,但返回的是 null
Authenticator authenticator=new Authenticator() {
@Override
public PasswordAuthentication requestPasswordAuthenticationInstance(String host, InetAddress addr, int port, String protocol, String prompt, String scheme, URL url, RequestorType reqType) {
return new PasswordAuthentication("xxxx", "xxxx".toCharArray());
}
};
HttpClient client = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_1_1)
.followRedirects(HttpClient.Redirect.NORMAL)
.connectTimeout(Duration.ofSeconds(20))
.proxy(ProxySelector.of(new InetSocketAddress("xxxxx",xxxx)))
.authenticator(authenticator)
.build();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(sinaUrl.getUrl()))
.header("Proxy-Authorization","Basic HIPD76B28I854FKD:D46CFF91FF69AFEF")
.header("CooKie", sinaRequestCache.getCookies())
.headers(sinaRequestCache.getHeaders())
.build();
HttpResponse<String> httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
求教,stackoverflow 上有个同样的问题,但是没有人回答