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

Reply via email to