title: Connection refused Android Api
body: <p>Good afternoon. I am trying to connect Android app to <a href="http://localhost:3000/" rel="nofollow noreferrer">http://localhost:3000/</a> ( but in code I use an emulator's ip). 
  The error is "W/System.err: java.net.ConnectException: Connection refused"
  Could you help me to find an error? Other posts were not useful for me. </p>
  
  <pre><code>    public String execute() {
          String line;
          StringBuilder outputStringBuilder = new StringBuilder();
          try {
              StringBuilder urlString = new StringBuilder(baseUrl + urlResource);
              if (!urlPath.equals("")) {
                  urlString.append("/" + urlPath); }
              if (parameters.size() &gt; 0 &amp;&amp; httpMethod.equals("POST")) {
                  payload = getPayloadAsString();
                  urlString.append("?" + payload);  }
              URL url = new URL(urlString.toString());
              String encoding = Base64Encoder.encode(email + ":" + password);
              HttpURLConnection connection = (HttpURLConnection) url.openConnection();
              connection.setRequestMethod(httpMethod);
              connection.setRequestProperty("Authorization", "Basic " + encoding);
              connection.setRequestProperty("Accept", "application/json");
              connection.setRequestProperty("Content-Type", "text/plain");
              connection.connect();
              if (httpMethod.equals("GET") || httpMethod.equals("PUT")) {
                 payload = getPayloadAsString();
                  connection.setDoInput(true);
                  connection.setDoOutput(true);
                  try {
                      OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
                      writer.write(payload);
                      headerFields = connection.getHeaderFields();
                      BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                      while ((line = br.readLine()) != null) {
                          outputStringBuilder.append(line);
                      }
                  } catch (Exception ex) {}
                  connection.disconnect();
              }
              else {
                  InputStream content = (InputStream) connection.getInputStream();
                  headerFields = connection.getHeaderFields();
                  BufferedReader in = new BufferedReader(new InputStreamReader(content));
                  while ((line = in.readLine()) != null) {
                      outputStringBuilder.append(line);}    }
          } catch (Exception e) {
              e.printStackTrace(); }
          if (!outputStringBuilder.toString().equals("")) {
              lastResponse = outputStringBuilder.toString(); }
          return outputStringBuilder.toString(); }}
  </code></pre>