UnknownHost异常

时间:2015-08-03 09:13:01

标签: android android-asynctask unknown-host

Heelo everyone,

我正在开发一个使用webservices的Android应用程序。 但是当我尝试连接时,我得到一个UnknownHostException。

我设法通过浏览器连接,似乎无法理解问题的来源。

这是我的logcat:

08-03 09:08:15.664: W/System.err(5828): java.net.UnknownHostException: Unable to resolve host "myhost.fr": No address associated with hostname
08-03 09:08:15.664: W/System.err(5828):     at java.net.InetAddress.lookupHostByName(InetAddress.java:426)
08-03 09:08:15.664: W/System.err(5828):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
08-03 09:08:15.664: W/System.err(5828):     at java.net.InetAddress.getAllByName(InetAddress.java:220)
08-03 09:08:15.664: W/System.err(5828):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:71)
08-03 09:08:15.664: W/System.err(5828):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
08-03 09:08:15.664: W/System.err(5828):     at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
08-03 09:08:15.664: W/System.err(5828):     at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
08-03 09:08:15.664: W/System.err(5828):     at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
08-03 09:08:15.664: W/System.err(5828):     at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
08-03 09:08:15.664: W/System.err(5828):     at libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
08-03 09:08:15.664: W/System.err(5828):     at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
08-03 09:08:15.664: W/System.err(5828):     at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
08-03 09:08:15.664: W/System.err(5828):     at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
08-03 09:08:15.664: W/System.err(5828):     at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:76)
08-03 09:08:15.664: W/System.err(5828):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:152)
08-03 09:08:15.664: W/System.err(5828):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
08-03 09:08:15.664: W/System.err(5828):     ... 25 more

这是执行连接的AsyncTask

    @Override
    protected SoapObject doInBackground(Void... params) {

        SoapSerializationEnvelope envelope = null;

        SoapObject service = null;
        HttpTransportSE transport = null;
        SoapObject soapResp = null;
        try {

            // configuring the envelope
            service = new SoapObject(NAMESPACE, METHOD_NAME);
            envelope = getSoapSerializationEnvelope(service);

            PropertyInfo pi1 = new PropertyInfo();
            pi1.setName("request");
            pi1.setValue(mRequest);
            pi1.setType(mRequest.getClass());
            service.addProperty(pi1);

            // creating the request
            transport = getHttpTransportSE();
            transport.debug = true;

            // sending the request
            soapResp = getServerResponse(transport, envelope);

        } catch (Exception e) {
            e.printStackTrace();
        }

        return soapResp;
    }

private SoapObject getServerResponse(HttpTransportSE transport, SoapSerializationEnvelope envelope) {
        SoapObject so = null;
        String requestDumpStr = null;

        try {
            transport.call(NAMESPACE + SOAP_ACTION_PREFIX + METHOD_NAME, envelope);
            requestDumpStr = transport.requestDump;

        } catch (Exception e1) {
            e1.printStackTrace();
        } 

        if (envelope.bodyIn != null) {

            try {
                so = (SoapObject) envelope.getResponse();
            } catch (SoapFault e) {
                e.printStackTrace();
            }

        }

        return so;
    }

 private final HttpTransportSE getHttpTransportSE() {
        HttpTransportSE ht = new HttpTransportSE(URL);
        ht.debug = true;
        return ht;
    }

0 个答案:

没有答案
相关问题