title: Java connection refused Mac OS Localhost Android studio
body: <p>I have a problem with a program I make on Android Studio in localhost
  :</p>
  
  <pre><code>01-11 21:07:07.957 23689-23689/mobile.shinam.com.studentco W/System.err: java.net.ConnectException: Connection refused
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at java.net.PlainSocketImpl.socketConnect(Native Method)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:334)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:196)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at java.net.Socket.connect(Socket.java:605)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at com.android.okhttp.internal.Platform.connectSocket(Platform.java:113)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at com.android.okhttp.Connection.connectSocket(Connection.java:196)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at com.android.okhttp.Connection.connect(Connection.java:172)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:329)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:126)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:46)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:68)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at mobile.shinam.com.studentco.LoginActivity.callPHPWebServiceForAuthenticate(LoginActivity.java:138)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at mobile.shinam.com.studentco.LoginActivity.wsAuthenticate(LoginActivity.java:70)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at mobile.shinam.com.studentco.LoginActivity.access$000(LoginActivity.java:24)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at mobile.shinam.com.studentco.LoginActivity$1.onClick(LoginActivity.java:55)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at android.view.View.performClick(View.java:5637)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at android.view.View$PerformClick.run(View.java:22429)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at android.os.Handler.handleCallback(Handler.java:751)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at android.os.Looper.loop(Looper.java:154)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6119)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
  01-11 21:07:07.959 23689-23689/mobile.shinam.com.studentco W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
  </code></pre>
  
  <p>I'm in localhost on a MacBook Pro, so no firewall, and there is my code :</p>
  
  <pre><code>    private String callPHPWebServiceForAuthenticate(String username, String password) {
          Log.w(TAG, "callPHPWebServiceForAuthenticate : start-end");
  //Settings
          String soap_url = "http://localhost/studentCo/bl/ws.php";//url du serveur SOAP
          String soap_action = "http://localhost/studentCo/bl/ws.php/wsAuthenticate";//le service interrogé
          String method_name = "wsAuthenticate";//La méthode
          String target_namespace = "urn:StudentCo";//voir wsdl : targetNameSpace ou tns
  //
          String wsResponse = null;
          SoapObject request = new SoapObject(target_namespace, method_name);
  //Params :
          PropertyInfo propInfo1 = new PropertyInfo();
          propInfo1.setName("username");
          propInfo1.setType(PropertyInfo.STRING_CLASS);
          propInfo1.setValue(username);
          request.addProperty(propInfo1);
  //
          PropertyInfo propInfo2 = new PropertyInfo();
          propInfo2.setName("password");
          propInfo2.setType(PropertyInfo.STRING_CLASS);
          propInfo2.setValue(password);
          request.addProperty(propInfo2);
          Log.w(TAG, request.toString());
  //Request-call
          SoapSerializationEnvelope envelope = new
                  SoapSerializationEnvelope(SoapEnvelope.VER11);
  //envelope.dotNet = true;//si le service est .NET based
          envelope.setOutputSoapObject(request);
          HttpTransportSE httpTransportSE = new HttpTransportSE(soap_url);
          try {
              httpTransportSE.call(soap_action, envelope);
              Object response = envelope.getResponse();
              wsResponse = response.toString();
              return wsResponse;
          }
          catch (IOException e) {
              e.printStackTrace();
              return null;
          }
          catch (XmlPullParserException e) {
              e.printStackTrace();
              return null;
          }
          catch (Exception e) {
              e.printStackTrace();
              return null;
          }
      }
  </code></pre>
  
  <p>If you have any way to unlock the problem :D 
  Dont know what more to say but I cant post i I dont write enough §§. I already search on google similar problem but none result mine, so I hope someone can help me :D</p>