Proxy settings in a java program

前端 未结 9 695
[愿得一人]
[愿得一人] 2020-12-14 12:09

I am trying to connect to a web service with a client generated from wsdl through a java program in eclipse. I am passing my request through a proxy server. But it seems tha

9条回答
  •  悲哀的现实
    2020-12-14 12:25

    I was able to get through the proxy by using the following piece of code.

    Added some new lines to Snehasish Code

    final String authUser = "username";
    final String authPassword = "password";
    Authenticator.setDefault(
       new Authenticator() {
          public PasswordAuthentication getPasswordAuthentication() {
             return new PasswordAuthentication(
                   authUser, authPassword.toCharArray());
          }
       }
    );
    url = new URL("http://www.somewebsite.com/sendmyrequest");
    
    connection = (HttpURLConnection) url.openConnection();
    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.setRequestMethod("POST");
    connection.setFollowRedirects(true);
    
    System.getProperties().put("http.proxyHost", "proxy.xyz.com");
    System.getProperties().put("http.proxyPort", "portNumber");
    System.setProperty("http.proxyUser", authUser);
    System.setProperty("http.proxyPassword", authPassword);
    System.getProperties().put("http.proxySet", "true");
    

提交回复
热议问题