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.
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 );
}
public class HttpHandler
{
private static final org.apache.commons.logging.Log LOG =
org.apache.commons.logging.LogFactory.getLog( HttpHandler.class );
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:
> 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.
> 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
> > 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
@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:
> Have the same error when trying just to create a socket connection :|
> On 29 Gen, 13:58, Rick Genter <rick_gen...@comcast.net> wrote:
> > 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 (Loggingin
> > > 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-
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:
> @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: > > Have the same error when trying just to create a socket connection :|
> > On 29 Gen, 13:58, Rick Genter <rick_gen...@comcast.net> wrote:
> > > 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 (Loggingin > > > > 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-
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:
> 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:
> > @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:
> > > Have the same error when trying just to create a socket connection :|
> > > On 29 Gen, 13:58, Rick Genter <rick_gen...@comcast.net> wrote:
> > > > 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 (Loggingin
> > > > > 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-
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:
> Hello!
> i am working on anandroidclient which is calling methods of a REST
> web service. I am using the commons HttpClient of theandroidapi.
> When i am calling a simple get method with HttpClient in theandroid
> emulator i get an exception, message is "Connection refused". I cant
> see any stacktrace, but this is a another problem (Logging inandroid??)
> 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 ofandroid
> everything works fine, response is ok, no error.
> Really strange: When i am calling the URL "http://www.google.com" WITH
> myandroidclient also everything works fine.