Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Connection Refused - HTTPClient

I doubt this is related to titanium. I am using MAMP and I am trying to access a PHP file. It works fine in the iPhone emulator, but if I try it on the android emulator, I get a connection refused error in my onerror method. Anyone know why this is happening?

— asked November 22nd 2010 by Ronnie Swietek
  • connection
  • refused
2 Comments
  • the best way to get an helpful answer in a timely manner is to provide some code

    — commented November 22nd 2010 by Aaron Saunders
  • Are you using MAMP? I figured mine out today actually. In the MAMP prefs,under the ports tab, I hit 'use default ports' and it sets the apache port to 80.

    Now when you make calls use your local ip address without a port number. ex: http://192.168.1.157/yourfile.php

    — commented December 15th 2010 by Ronnie Swietek

9 Answers

  • From http://developer.android.com/resources/faq/commontasks.html#localhostalias

    > If you need to refer to your host computer's localhost, such as when you want the emulator client to contact a server running on the same host, use the alias 10.0.2.2 to refer to the host computer's loopback interface. From the emulator's perspective, localhost (127.0.0.1) refers to its own loopback interface.

    You'll need to point to your actual IP address, your internal internal IP address, or 10.0.2.2

    — answered March 16th 2011 by Noah Litvin
    permalink
    2 Comments
    • I replace localhost to 10.0.2.2.

      Works fine!

      — commented May 18th 2012 by Fernando Rosa
    • Pointing to my internal ip address works for me.
      I am using 3.3.0 SDK.

      — commented August 6th 2014 by Handinata Tanudjaja
  • Are you using MAMP? I figured mine out today actually. In the MAMP prefs,under the ports tab, I hit 'use default ports' and it sets the apache port to 80.
    Now when you make calls use your local ip address without a port number. ex: http://192.168.1.157/yourfile.php

    — answered December 15th 2010 by Ronnie Swietek
    permalink
    1 Comment
    • I'm using XAMPP Lite and it by default uses port 80 with 8080 being the fall back; I tried with the IP that shows in XAMPP's panel (i.e. 127.0.0.1 alt. to writing localhost) but it doesn't seem to work; using your actual IP address (http://www.whatismyip.com/) followed by "yourfile.php" seems to work however.

      — commented December 15th 2010 by daniyal hamid
  • Hmm ok.. Not doing anything out of the ordinary here. Works on the iphone, fails on the android emulator

    loginBtn.addEventListener('click',function(e)
    {
        if (username.value != '' && password.value != '')
        {
            loginReq.open("POST","http://localhost:8888/post_auth.php");
            var params = {
                username: username.value,
                password: Ti.Utils.md5HexDigest(password.value)
            };
            loginReq.send(params);
        }
        else
        {
            alert("Username/Password are required");
        }
    });
    
    — answered November 22nd 2010 by Ronnie Swietek
    permalink
    0 Comments
  • I am still searching for this answer if anyone has any idea?

    — answered November 29th 2010 by Ronnie Swietek
    permalink
    0 Comments
  • Localhost is the issue here, it doesn't work on Android for some reasons, mapped internally.

    — answered December 1st 2010 by Brice Lechatellier
    permalink
    0 Comments
  • well since localhost is the issue, I changed it to my internal IP http://192.168.1.157:8888/post_auth.php and it is now crashing the application (on android, iphone still works)…hmmm

    — answered December 2nd 2010 by Ronnie Swietek
    permalink
    0 Comments
  • I'm having the same problem on android emulator (when trying to establish a connection to localhost via HTTPClient); I keep getting connection refused. Does anyone have a solution?

    — answered December 14th 2010 by daniyal hamid
    permalink
    0 Comments
  • I'm Getting the same issue!! On Android Emulator i can't open a HTTPClient with localhost. I haven't test with iPhone because I dont have Mac.
    Any solution?!

    Thanks!

    — answered February 1st 2011 by Handel Das Vire
    permalink
    1 Comment
    • So, this is a bug of Titanium or android emulator?! There's any possibility to be solved?!

      — commented February 1st 2011 by Handel Das Vire
  • Sending error Connection to http://localhost:8888 refused

    how can i solved?

    — answered March 20th 2012 by Dharmik Patel
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.