2

I have setup a simple Node.js local server with express that returns a json like this

    router.get('/addUser', function(req, res, next) {
    res.send('{ "result" : "FAILED", "error" : "TEST" }');
});

Node.js listens to localhost port 3000, so when connect to localhost:3000/addUser I expect to get back this json { "result" : "FAILED", "error" : "TEST" }

When I try to call the above url from Android Emulator to 10.0.2.2:3000 (Android IP for localhost) with HttpURLConnection I get an exception :*java.io.IOException: unexpected end of stream on Connection{10.0.2.2:3000, proxy=DIRECT@ hostAddress=10.0.2.2 cipherSuite=none protocol=http/1.1} (recycle count=0).*

When using a browser or postman to test my node.js server at http://localhost:3000/addUser it returns the json object correctly.

When I try to communicate from Android to a local Apache Server to a page returning the same json it works correctly.

Something goes wrong when conenecting from Android emulator to local Node.js server.

D.J
  • 1,439
  • 1
  • 12
  • 23
Andreas Oikonomou
  • 3,257
  • 2
  • 13
  • 13

1 Answers1

3

Finally the problem was caused by a space in querystring. Browser and Postman seem to detect and automatically correct this error.

Andreas Oikonomou
  • 3,257
  • 2
  • 13
  • 13