I know I am posting to a thread thats been dead for ages, but I guess now 
replacing localhost with 10.0.2.2 solves the problem... correct?

On Monday, 11 February 2008 14:43:50 UTC+5:30, kevin wrote:
>
> 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. 
> > 
> > Whats the problem of theandroidHttpClient with the 
> Urlhttp://localhost/itsmyphone-server/rest/this/is/a/method?Is there a 
> > "feature" inandroidto accept only Urls starting withhttp://
> 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; 
> > importandroid.app.Activity; 
> > importandroid.os.Bundle; 
> > importandroid.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 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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to