网友,你是Applet还是Application。怎么还有java -Dhttp.proxyHost=proxyHost?

解决方案 »

  1.   

    本来是App的,我用 java -Dhttp.proxyHost=proxyHost hello  。但我想转成 Applet程序,因为用了 URL,URLConnection, 所以在运行时要加入参数
    才能运行。
      

  2.   

    我估计可能有问题。
    你是想在applet里用别的服务器的数据啊。如果是的话。你要求不可能实现。因为applet只能与来源服务器通信。你能说的更清楚点吗?
      

  3.   

    java -DproxySet=true -DproxyHost=myProxyServer.come -DproxyPort=80 MyJavaApp
     
    Or in your source : import java.util.Properties;
    ...Properties systemSettings = System.getProperties();
    systemSettings.put("proxySet", "true");
    systemSettings.put("proxyHost", "myProxyServer.com");
    systemSettings.put("proxyPort", "80");
    System.setProperties(systemSettings); --------------------------------------------------------------------------------
    NOTE:
    You might need to identify yourself to the proxy server. Use the HTTP property "Proxy-Authorization" with a username:password base64 encoded. Properties systemSettings = System.getProperties();
    ...
    System.setProperties(systemSettings);URL url=new URL("http://someserver/somepage");
    URLConnection uc = url.openConnection ();
    String encoded = new String(Base64.base64Encode(new String("username:password").getBytes()));
    uc.setRequestProperty("Proxy-Authorization", "Basic " + encoded);
    uc.connect(); 
      

  4.   

    skyyoung(路人甲)的方法还是只能用于application,对于applet还是不行。
    这样做是想干什么呢,难道有什么用吗?
      

  5.   

    我会试一试skyyoung(路人甲)大侠的方法。
    先多谢各位大侠的热心帮助!!请问为什么要加如下语句:String encoded = new String(Base64.base64Encode(new String("username:password").getBytes()));
    uc.setRequestProperty("Proxy-Authorization", "Basic " + encoded);先谢了!!!
      

  6.   

    我会试一试skyyoung(路人甲)大侠的方法。
    先多谢各位大侠的热心帮助!!请问为什么要加如下语句:String encoded = new String(Base64.base64Encode(new String("username:password").getBytes()));
    uc.setRequestProperty("Proxy-Authorization", "Basic " + encoded);先谢了!!!
      

  7.   

    为了表示感谢各位大侠的参与,我先给 大家 10 分:
     yangzi(笨笨)
     skyyoung(路人甲) 
     lmy2000(pluto)