Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java默认身份验证与代理的参数_Java_Proxy_Arguments - Fatal编程技术网

Java默认身份验证与代理的参数

Java默认身份验证与代理的参数,java,proxy,arguments,Java,Proxy,Arguments,我已经搜索了很多关于这个主题的内容,但不明白为什么如果我尝试在java应用程序中使用web服务,如果不使用这个代码段实现,我会失败: final String authUser = "myUser"; final String authPassword ="******"; Authenticator.setDefault( new Authenticator() { public PasswordAuthentication getPasswo

我已经搜索了很多关于这个主题的内容,但不明白为什么如果我尝试在java应用程序中使用web服务,如果不使用这个代码段实现,我会失败:

final String authUser = "myUser";
    final String authPassword ="******";
    Authenticator.setDefault(
       new Authenticator() {
          public PasswordAuthentication getPasswordAuthentication() {
             return new PasswordAuthentication(
                   authUser, authPassword.toCharArray());
          }
       }
    );
…我不喜欢在这里或属性文件中“雕刻”我的凭据。 我更喜欢使用“Run as”vm参数……因此,如果我对上面的代码进行注释并使用以下参数运行我的应用程序:

-Dhttps.proxyHost=proxy.test.it 
-Dhttp.proxyPort=3128 
-Dhttp.proxyUsername=myUser  
-Dhttps.proxyPassword=**** 
-Danypoint.platform.proxy_username=myUser 
-Danypoint.platform.proxy_password=**** 
-Danypoint.platform.proxy_host=proxy.test.it 
-Danypoint.platform.proxy_port=3128 
-Djava.net.useSystemProxies=true
-Dhttp.nonProxyHosts=...
或者

这行不通。我真的不明白


谢谢你的支持

我不确定您到底想要实现什么,但是如果您通过这样的虚拟机服务器传入数据

-Dhttp.proxyUsername=myUser  
-Dhttps.proxyPassword=**** 
您可以这样访问数据

String authUser = System.getProperty("http.proxyUser");

您可以始终执行
String authUser=System.getProperty(“http.proxyUser”)
,这样它的值就不会在代码中硬编码,而是从cmd linesure读取,但它不起作用!请读我的句子。如果且仅当我放入第一个java脚本时,调用不会失败……这种方法确实有效。你用得不对。不要两次声明
authUser
。(在您的示例中,您已将其标记为
final…
。如果您按照上述操作,您的应用程序将按照您的意愿工作。如果我希望完全避免这段代码?如果没有该java代码段,它将无法工作?正如我所说,我已对这部分进行了注释…您希望避免在v中设置用户名吗“代码”> AuthoSudio/Cube >什么代码?你不希望在那里有一个代码。“请不要考虑变量。我只想用ARGS成功运行我的代码……没有初始代码段。只是把值传递给VM。这是行不通的。PASSWORDVICE需要知道用户名和密码,并且你必须告诉我。它不会在args中查找它们。
String authUser = System.getProperty("http.proxyUser");