I am trying to call a REST webservice from an Android app that I am running on an emulator. I can call the service from my browser with
http://localhost:39064/AndroidServiceImpl.svc/submitexcerpt?excerpt=...and+the+pirate+fell+off+the+boat
I can call the service from my emulator with
http://10.0.2.2:39064/AndroidServiceImpl.svc/submitexcerpt?excerpt=...and+the+pirate+fell+off+the+boat
But when I run this code:
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response1;
response1 = httpclient.execute(new HttpGet("http://10.0.2.2:39064/AndroidServiceImpl.svc/submitexcerpt?excerpt=testingthisout"));
I get a connection refused exception. I have added the <user-permission android:name="android.permission.INTERNET"></user-permission> to my Manifest file, and set the ThreadPolicy to LAX but still no luck. Any Suggestions?
I got the answer rather than putting
<user-permission android:name="android.permission.INTERNET"></user-permission>I needed
<uses-permission android:name="android.permission.INTERNET"></uses-permission>So just some bullet points on calling a webservice:
*add to Manifest.xml file
<uses-permission android:name="android.permission.INTERNET"></uses-permission><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>*use 10.0.2.2 rather than localhost for a locally consumed service
*Set the Thread Policy to lax(not recommended for production) or use AsyncTask
ThreadPolicy tp = ThreadPolicy.LAX;StrictMode.setThreadPolicy(tp);