The following address from the emulator docs might be what you want: >10.0.2.2 Special alias to your host loopback interface (i.e., 127.0.0.1 >on your development machine)
Test it in the emulator's android browser before worrying about your code On Sep 21, 3:18 pm, John Gaby <jg...@gabysoft.com> wrote: > Thanks for the reply. I have tried using the IP address of the host > machine like this: > > String urlServer = "http://192.168.1.101:3571/mycmd.aspx? > command=test"; > > but when I do that, my program times out on the > 'connection.getOutputStream' call. I am also not sure I see how this > would work anyway, since I an not able to access my local server by > using that IP address, even from a browser. > > Thanks > > On Sep 21, 11:22 am, Hotouch <hoto...@gmail.com> wrote: > > > if you are testing this on your emulator then you have to change > > localserver to your ip because emulator is it self a localserver. > > > open your cmd and write "ipconfig/all" tp get your system ip and then > > place your ip instead of localhost and it should work this time :) > > > Thanks > > > On Sep 21, 10:11 pm, John Gaby <jg...@gabysoft.com> wrote: > > > > I am trying to do an HTTP POST of some data. The following is a test > > > routine that I wrote to try and accomplish this: > > > > void Put() > > > { > > > HttpURLConnection connection = null; > > > DataOutputStream outputStream = null; > > > > String urlServer = > > > "http://localhost:3571/mycmd.aspx?command=test"; > > > String message = "This is a message"; > > > > try > > > { > > > URL url = new URL(urlServer); > > > connection = (HttpURLConnection) > > > url.openConnection(); > > > > // Allow Inputs & Outputs > > > connection.setDoInput(true); > > > connection.setDoOutput(true); > > > connection.setUseCaches(false); > > > > // Enable POST method > > > connection.setRequestMethod("POST"); > > > > connection.setRequestProperty("Connection", > > > "Keep-Alive"); > > > connection.setRequestProperty("Content-Type", > > > "application/octet- > > > stream"); > > > > outputStream = new > > > DataOutputStream( connection.getOutputStream() ); > > > outputStream.writeBytes(message); > > > > // Responses from the server (code and message) > > > int serverResponseCode = > > > connection.getResponseCode(); > > > String serverResponseMessage = > > > connection.getResponseMessage(); > > > > outputStream.flush(); > > > outputStream.close(); > > > } > > > catch (Exception ex) > > > { > > > int i = 0; > > > //Exception handling > > > } > > > } > > > > If I set urlServer to 'localhost' I get an exception: > > > > java.net.ConnectException: localhost/127.0.0.1:3571 - Connection > > > refused > > > > I am presuming that this is because the localhost is not being > > > resolved properly to my host machine (I am running under the > > > emulator). Is there a way to access a localhost server on my host > > > machine from the emulator, or do I need a real IP address? > > > > Thanks > > -- 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