我正在使用以下代码,但始终有错误:
public static void connect(CloudCredentials credentials, final CloudProxy proxy) throws Exception {
ApplicationTokenCredentials azCredential = new ApplicationTokenCredentials(credentials.getClientID(),
credentials.getTenantID(), credentials.getClientKey(), AzureEnvironment.AZURE);
try {
Configurable config = Azure.configure()
.withConnectionTimeout(30, TimeUnit.SECONDS)
.withReadTimeout(60, TimeUnit.SECONDS);
if (proxy != null) {
config.withProxy(new Proxy(Type.HTTP, new InetSocketAddress(proxy.getProxyHost(), proxy
.getProxyPort())));
if (proxy.getProxyUsername() != null && proxy.getProxyUsername().trim().length() > 0) {
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(proxy.getProxyUsername(), proxy.getProxyPassword()
.toCharArray());
}
});
config.withProxyAuthenticator(new JavaNetAuthenticator());
}
}
Authenticated authenticate = config.authenticate(azCredential);
authenticate.withSubscription(credentials.getSubscription()).getCurrentSubscription().displayName();
System.out.println(authenticate);
} catch (Exception e) {
System.out.println(e);
}
}
[pool-1-thread-1]错误com.microsoft.aad.adal4j.authenticationcontext- [相关ID:]请求获取令牌失败。java.io.ioexception:无法通过代理进行隧道。代理返回" http/1.1 407代理身份验证" 在sun.net.www.protocol.http.httpurlconnection.dotunnelning(httpurlConnection.java:2124) 在sun.net.www.protocol.https.abstractdelegatehttpsurlconnection.connect(AbstractDelegateHttpSurlConnection.java:183) 在sun.net.www.protocol.http.httpurlconnection.getOutputStream0(httpurlConnection.java:1316) 在sun.net.www.protocol.http.httpurlconnection.getOutputStream(httpurlConnection.java:1291) 在sun.net.www.protocol.https.httpsurlconnectionimpl.getOutputStream(httpsurlConnectionImpl.java:250) 在com.microsoft.aad.adal4j.adaloauthrequest.configureheaderheaderandexecuteoauthcall(adaloauthrequest.java:140) 在com.microsoft.aad.adal4j.adaloauthrequest.send(adaloauthrequest.java:83) 在com.microsoft.aad.adal4j.adaltokenrequest.executeoauthrequestandprocessresponse(adaltokenRequest.java:80) 在com.microsoft.aad.adal4j.authenticationcontext.acquiretokencommon(AuthenticationContext.java:818) 在com.microsoft.aad.adal4j.authenticationcontext.access $ 100(AuthenticationContext.java:66) 在com.microsoft.aad.adal4j.authenticationcontext $ 1.CALL(AuthenticationContext.java:174) 在com.microsoft.aad.adal4j.authenticationcontext $ 1.CALL(AuthenticationContext.java:163) 在java.util.concurrent.futuretask.run(futuretask.java:266) at Java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) at Java.util.concurrent.threadpoolexecutor $ worker.run(threadpoolexecutor.java:617) 在java.lang.thread.run(thread.java:745)java.lang.runtimeException:java.io.io.ioexception:java.io.ioexception:无法通过代理进行隧道。代理返回" http/1.1 407代理身份验证"
但是代理我确定还可以。我还有另一个测试代码。它运行良好:
String a = "111";
System.out.print(a.toCharArray());
Authenticator.setDefault(new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("test", "111".toCharArray());
}
});
URLConnection connection;
try {
connection = new URL(
"http://devio.us/~ricky/stackoverflow-protected/nothingtosee.html")
.openConnection(new Proxy(Type.HTTP, new InetSocketAddress("192.168.1.59", 808)));
System.out.println(new BufferedReader(new InputStreamReader(
connection.getInputStream(), "UTF-8")).readLine());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
我不想使用system.setProperty设置代理,因为所有Java连接的所有Java都会通过代理。在Azure文档中,我找不到任何代理信息。谁能帮我?非常感谢。
现在,设置隧道时需要基本身份验证的代理 因为HTTPS将不再成功。如果需要,这个 身份验证方案可以通过从 jdk.http.auth.tunneling.disabledschemes网络属性,或 将同名的系统属性设置为"(空) 命令行。
您可以从禁用HTTPS隧道的基本身份验证中找到它。
因此,您可以在jdk/jre/lib directory
中找到net.properties
文件。(对我来说,是C:Program FilesJavajdk1.8.0_144jrelib
)。
然后更改变量
jdk.http.auth.tunneling.disabledSchemes
jdk.http.auth.proxying.disabledSchemes
供空喜欢:
jdk.http.auth.tunneling.disabledSchemes=
jdk.http.auth.proxying.disabledSchemes=
请重试您的代码。任何问题,请随时让我Kown。