Android: ksoap, "UnknownHostException: host unresolved" depending on API

Thank you for attention.

I have a problem using ksoap2 to call a web service via android.

I have a web service call function.

public String CallWebServiceFunction() { String WSDL_TARGET_NAMESPACE = "http://MyWeb.com/"; String SOAP_ADDRESS = "http://MyWeb.com/pvws.asmx"; String SOAP_ACTION = "http://MyWeb.com/SoapAction"; String OPERATION_NAME = "SoapAction"; SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME); PropertyInfo prop1 = new PropertyInfo(); prop1.setName("prop1"); prop1.setValue("1"); request.addProperty(prop1); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS); Object response=null; try { httpTransport.call(SOAP_ACTION, envelope); response = envelope.getResponse(); } catch (Exception exception) { response=exception.toString(); } return response.toString(); } 

When I use an emulator (or a real device) that uses API 16 or higher (Android 4.x) - everything is fine , the function receives the correct answer from webservice. But when I use an emulator (or real device) with API 7 (Android 2.x) - then I get an exception

"java.net.UnknownHostException: Host not resolved: MyWeb.com:80"

I use the same code in both cases, trying one after another - and get different results

Does anyone have any ideas?

UPD1 : permission section from my manifest

 <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 

UPD2 : Hypothesis . I originally created my application for targetSdkVersion = 16. Therefore, I use multi-threaded code when I call webservice over the Internet. Maybe when it works with API7, the source code should not be multithreaded?

UPD3 . The hypothesis was wrong. Calling a webservice from the main thread throws the same exception.

But I noticed that when I run my project on another computer - it works correctly. Despite the fact that I use the same code.

+4
source share
3 answers
 UnknownHostException:host is unresolved 

Make sure you add permissions to your AndroidManifest.xml , like this

 <uses-permission android:name="android.permission.INTERNET" /> 

and also make sure that it is added inside the <manifest> not inside any other tags such as <application> , etc.

PS.

Also make sure for the following permissions

 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
+1
source

I think Android.permission.READ_PHONE_STATE is missing for Android 2.x.

Try

0
source

Please check your data connection or Wi-Fi is turned on.

then go to the manifest and check for internet

 <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
0
source

Source: https://habr.com/ru/post/1502031/


All Articles