title: Using proxies with Google HTTP Client Library for Java
body: <p>I use Google HTTP Client Library for Java to make simple JSON requests and parse responses. It works well when I don't go through a proxy. But now I'd like to allow my users to use a proxy (with authentication) functionality in my application. I looked in the HttpTransport, HttpRequestFactory and HttpRequestInitializer classes without any success.</p>
  
  <p>I've only slightly modified the examples so far (and mostly it was removing unnecessary code). So where in the code do I add the proxy settings?</p>
  
  <pre><code>static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
  static final JsonFactory JSON_FACTORY = new JacksonFactory();
  
  &lt;T&gt; T get(String url, Class&lt;T&gt; type) throws IOException {
      HttpRequestFactory requestFactory =
              HTTP_TRANSPORT.createRequestFactory(new HttpRequestInitializer() {
                  @Override
                  public void initialize(HttpRequest request) {
  
                      request.setParser(new JsonObjectParser(JSON_FACTORY));
                  }
              });
      HttpRequest request = requestFactory.buildGetRequest(new GenericUrl(url));
      return request.execute().parseAs(type);
  }
  </code></pre>