Wednesday, November 16, 2011

[android-developers] Re: org.apache.http.conn.HttpHostConnectException: Connection to http://127.0.0.1:8080 refused

Also check the port number to which you are supposed tp connect.

On Nov 17, 4:30 am, alexb <alexboot...@gmail.com> wrote:
> 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 <indra4...@gmail.com> 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment