title: Proxy With Java URLConnection class
body: <p>I am very new with Java. I am using following code for the calling REST API, its working fine in simple environment but when I used with proxy environment Its throwing the <strong>NullPointerException</strong>. I found result on google that we have to set proxy setting for that. I set proxy according to that <a href="http://www.javaworld.com/javaworld/javatips/jw-javatip42.html" rel="noreferrer">http://www.javaworld.com/javaworld/javatips/jw-javatip42.html</a> article but this is not working + <strong>base64Encode( password )</strong> creating syntax error.</p>
  
  <pre><code>URL url = new URL("http://examplerestapi/get/user");
  URLConnection yc = url.openConnection();
  
  
  
  in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
  String inputLine;
  
  while ((inputLine = in.readLine()) != null) {
         sb.append(inputLine);
  }
  
  String res = sb.toString();
  </code></pre>
  
  <p>please help me to set proxy Host, port , username and password.</p>