Java连接拒绝Mac OS Localhost Android工作室

时间:2017-01-11 20:19:00

标签: java android macos

我在localhost上的Android Studio上制作的程序有问题 :

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)

我在MacBook Pro的本地主机上,所以没有防火墙,而且还有我的代码:

    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;
        }
    }

如果您有任何解决问题的方法:D 不知道还有什么要说但我不能发帖我不够写§§。我已经在搜索谷歌类似的问题,但没有结果我的,所以我希望有人可以帮助我:D

0 个答案:

没有答案