Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
HttpClient, connection refused, localhost
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
n2  
View profile  
 More options Jan 29 2008, 6:09 am
From: n2 <daniel.mury...@googlemail.com>
Date: Tue, 29 Jan 2008 03:09:26 -0800 (PST)
Local: Tues, Jan 29 2008 6:09 am
Subject: HttpClient, connection refused, localhost
Hello!
i am working on  an android client which is calling methods of a REST
web service. I am using the commons HttpClient of the android api.
When i am calling a simple get method with HttpClient in the android
emulator i get an exception, message is "Connection refused".  I cant
see any stacktrace, but this is a another problem (Logging in
android??)

The (dummy) URL which is called: http://localhost/itsmyphone-server/rest/this/is/a/method
When i am loading this URL with my browser everything is fine. When i
am calling this Url by HttpClient in a JUnit test outside of android
everything works fine, response is ok, no error.

Really strange: When i am calling the URL "http://www.google.com" WITH
my android client also everything works fine.

Whats the problem of the android HttpClient with the Url
http://localhost/itsmyphone-server/rest/this/is/a/method? Is there a
"feature" in android to accept only Urls starting with http://www.google.com?

Here is my code:

-- Class 1: HalloAndroid --

package org.n2.android.hallo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class HalloAndroid extends Activity {

    private static final Log LOG =
LogFactory.getLog( HalloAndroid.class );

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        TextView tv = new TextView( this );
        HttpHandler httpHandler = new HttpHandler();
        try
        {
          tv.setText( httpHandler.executeGet() );
        }
        catch( Exception e )
        {
          LOG.error( "Error while executing HTTP method: ", e );
          tv.setText( "Error while executing HTTP method: " +
e.getMessage() );
        }
        setContentView( tv );
    }

}

-- Class 2: HttpHandler --

package org.n2.android.hallo;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;

public class HttpHandler
{
  private static final org.apache.commons.logging.Log LOG =
org.apache.commons.logging.LogFactory.getLog( HttpHandler.class );

  private static final String URL = "http://localhost/itsmyphone-
server/this/is/a/method" ;
  //private static final String URL = "http://www.google.com";

  public String executeGet()
  {
    String result = null;
    HttpClient httpClient = new HttpClient();
    GetMethod getMethod = new GetMethod( URL );
    try
    {
      httpClient.executeMethod( getMethod );
      result = getMethod.getResponseBodyAsString();
    }
    catch( Exception e )
    {
      LOG.error( "Error while excecuting HTTP method. URL is: " + URL,
e );
      throw new RuntimeException( "Error while excecuting HTTP method.
URL is: " + URL + ", Cause: " + e.getMessage(), e);
    }
    return result
  }

}

Can you help me? Thank you!
Daniel / n2

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Digit  
View profile  
 More options Jan 29 2008, 6:25 am
From: Digit <digit.andr...@gmail.com>
Date: Tue, 29 Jan 2008 12:25:47 +0100
Local: Tues, Jan 29 2008 6:25 am
Subject: Re: [android-developers] HttpClient, connection refused, localhost

within the emulated system, "localhost" will translate into 127.0.0.1  which
is the device's own loopback interface, and not the one on your PC.
the connection is refused simply because the HttpClient doesn't find any
server running on the device.

you need to address the server differently, for example try using the IP
address of one of your non-loopback interfaces. this assumes that the server
did bound to 0.0.0.0 or this specific address, and not to the host's
loopback 127.0.0.1

hope this helps,

On Jan 29, 2008 12:09 PM, n2 <daniel.mury...@googlemail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rick Genter  
View profile  
 More options Jan 29 2008, 7:58 am
From: Rick Genter <rick_gen...@comcast.net>
Date: Tue, 29 Jan 2008 04:58:09 -0800
Local: Tues, Jan 29 2008 7:58 am
Subject: Re: [android-developers] HttpClient, connection refused, localhost
On Jan 29, 2008, at 3:09 AM, n2 wrote:

> Hello!
> i am working on  an android client which is calling methods of a REST
> web service. I am using the commons HttpClient of the android api.
> When i am calling a simple get method with HttpClient in the android
> emulator i get an exception, message is "Connection refused".  I cant
> see any stacktrace, but this is a another problem (Logging in
> android??)

> The (dummy) URL which is called: http://localhost/itsmyphone-server/rest/this/is/a/method
> When i am loading this URL with my browser everything is fine. When i
> am calling this Url by HttpClient in a JUnit test outside of android
> everything works fine, response is ok, no error.

You can't use localhost; localhost is the (emulated) phone. You need  
to specify the IP address or DNS name of the actual web server.
--
Rick Genter
rick_gen...@comcast.net

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
n2  
View profile  
 More options Jan 29 2008, 11:27 am
From: n2 <daniel.mury...@googlemail.com>
Date: Tue, 29 Jan 2008 08:27:26 -0800 (PST)
Local: Tues, Jan 29 2008 11:27 am
Subject: Re: HttpClient, connection refused, localhost
On 29 Jan., 13:58, Rick Genter <rick_gen...@comcast.net> wrote:

> You can't use localhost; localhost is the (emulated) phone. You need
> to specify the IP address or DNS name of the actual web server.

On the "phone" localhost is the phone...
Stupid me. Thank you Rick and Digit and sorry for wasting your time!

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
cyberziz  
View profile  
 More options Feb 1 2008, 4:33 am
From: cyberziz <alessandro.zo...@gmail.com>
Date: Fri, 1 Feb 2008 01:33:54 -0800 (PST)
Local: Fri, Feb 1 2008 4:33 am
Subject: Re: HttpClient, connection refused, localhost
Have the same error when trying just to create a socket connection :|

On 29 Gen, 13:58, Rick Genter <rick_gen...@comcast.net> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
n2  
View profile  
 More options Feb 2 2008, 3:17 pm
From: n2 <daniel.mury...@googlemail.com>
Date: Sat, 2 Feb 2008 12:17:52 -0800 (PST)
Local: Sat, Feb 2 2008 3:17 pm
Subject: Re: HttpClient, connection refused, localhost
@cyberziz:
When you are running the emulator the emulator itself is localhost. To
create a connection to your workstation you have to use the ip of the
workstation (e.g.: 192.168.0.1). On windows run "ipconfig" on linux
"ifconfig" in a text console to see your ip.
When you use this ip instead of localhost on emulator everything works
fine.
-Daniel

On 1 Feb., 10:33, cyberziz <alessandro.zo...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Renato  
View profile  
 More options Feb 4 2008, 12:19 pm
From: Renato <nazcaspi...@googlemail.com>
Date: Mon, 4 Feb 2008 17:19:58 +0000
Local: Mon, Feb 4 2008 12:19 pm
Subject: Re: [android-developers] Re: HttpClient, connection refused, localhost

What if you don't have a network connection so you don't have an IP other
than 127.0.0.1 (ipconfig says media disconnected). Is there any way you can
tell windows to use other IP as the loopback?

I tried to change the "hosts" file, but it doesn't help.

Cheers

R

On Feb 2, 2008 8:17 PM, n2 <daniel.mury...@googlemail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Charlie Collins  
View profile  
 More options Feb 4 2008, 1:05 pm
From: Charlie Collins <charlie.coll...@gmail.com>
Date: Mon, 4 Feb 2008 10:05:50 -0800 (PST)
Local: Mon, Feb 4 2008 1:05 pm
Subject: Re: HttpClient, connection refused, localhost
If you want use TCPIP networking, between the emulator and your host,
you will have to have an ip address (not just the loopback 127.0.0.1).
If you get nothing with "ipconfig /all" then you need to setup an
adapter and configure it (not just name resolution, which is what the
hosts file does, sometimes, depending on other settings).

If you are sending email and such to this thread though, from that
same machine, you have more than the loopback - check again. If that's
an isolated machine without any physical adapters, such that it really
doesn't have an ip address other than the loopback, then it's not a
good dev machine for android and the emulator, etc. (It can be a local
network only, static hand configured ip address if need be, but it
will have to have an address.)

On Feb 4, 12:19 pm, Renato <nazcaspi...@googlemail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
kevin  
View profile  
 More options Feb 11 2008, 4:13 am
From: kevin <kevindor...@gmail.com>
Date: Mon, 11 Feb 2008 01:13:50 -0800 (PST)
Local: Mon, Feb 11 2008 4:13 am
Subject: Re: HttpClient, connection refused, localhost
HI,
are u able to retrieve data from the localhost server and display it
on to the android application?if yes, can u help me out in sending me
ur source code so that i can also learn how to. can u let me know one
more thing,are u retreiveing data as XMl formatfrom server or as
normal string.please let em know ur serer also.is it apache or jboss?
please help me out

On Jan 29, 4:09 pm, n2 <daniel.mury...@googlemail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »