First, 127.0.0.1 is not valid on the device. Second, check that your app has <uses-permission android:name="android.permission.INTERNET" />
On Nov 16, 1:38 am, indra <[email protected]> wrote: > I am trying to call a servlet from andorid application but when i > call the servlet i get the connection refused error > I have tried replacing 127.0.0.1 with my ip iaddress the i get > connection time out error any clue on these. > > public static String executeHttpPost(String url, > ArrayList<NameValuePair> postParameters) throws Exception { > BufferedReader in = null; > HttpClient client = getHttpClient(); > System.out.println("=======1"); > HttpPost request = new HttpPost(url); > UrlEncodedFormEntity formEntity = new > UrlEncodedFormEntity(postParameters); > request.setEntity(formEntity); > System.out.println("=======2"); > HttpResponse response = client.execute(request); > > } > > public class LoginExcerciseActivity extends Activity { > > @Override > public void onCreate(Bundle savedInstanceState) { > > try { > Class > strictModeClass=Class.forName("android.os.StrictMode"); > Class > strictModeThreadPolicyClass=Class.forName("android.os.StrictMode > $ThreadPolicy"); > Object laxPolicy = > strictModeThreadPolicyClass.getField("LAX").get(null); > Method method_setThreadPolicy = > strictModeClass.getMethod( > "setThreadPolicy", strictModeThreadPolicyClass ); > method_setThreadPolicy.invoke(null,laxPolicy); > } catch (Exception e) { > System.out.println("===========>Error giving policy"); > e.printStackTrace(); > } > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > ArrayList<NameValuePair> postParameters = new > ArrayList<NameValuePair>(); > postParameters.add(new BasicNameValuePair("username", > un.getText().toString())); > postParameters.add(new BasicNameValuePair("password", > pw.getText().toString())); > System.out.println("===About to send request"); > response = CustomHttpClient.executeHttpPost("http:// > 127.0.0.1:8080/MobileProj/androidres.do", postParameters); > > > > > > > > } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

