Troubleshooting‎ > ‎

Connect Through a Proxy

If you have difficulties connecting to your REST API from your programming environment, but API Creator is working as expected, the most likely explanation is that your browser is using a proxy to connect to the web. This is common in large organizations, and is typically used to filter web traffic for security reasons.

If this is the case, look at your browser settings and determine the address and port number of your proxy server. Once you have this information, setting up your program to use the proxy depends entirely on your programming platform.

Java

In Java, failure to connect shows as an exception similar to the following:

Exception in thread "main" org.apache.http.conn.HttpHostConnectException: Connection to http://servername.espressologic.com refused
       at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:127)
       at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:147)
       at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:101)
       at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:381)
       at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
       at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576)
       at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554)

To use a proxy:

  1. Set the following system properties:
    System.setProperty("http.proxyHost", "proxyname"); // Enter your proxy name here
    System.setPropery("http.proxyPort", "8080");
  2. If the proxy requires authentication, add the following:
    Authenticator authenticator = new Authenticator() {
        public PasswordAuthentication getPasswordAuthentication() {
            return (new PasswordAuthentication("user", "password".toCharArray()));
        }
    };
    Authenticator.setDefault(authenticator);

JavaScript

JavaScript in the browser uses the browser's proxy settings, and therefore should never be a problem. You can have Server-side JavaScript (for example, Node.js) use a proxy by routing all traffic through the proxy, for example:

var http = require('http');
var google = http.createClient(3128, 'your.proxy.host');
var request = google.request('GET', '/',
  {'host': 'www.google.com'});
request.end();

Other languages have different conventions, which also depend on which framework(s) and libraries you may be using.