I was using localhost
for the address, which was obviously wrong. After replacing it with the IP address of the server (in the network that emulator is), it worked perfectly.
Edit
In Android Emulator, the address of the development machine is 10.0.2.2
. More explanation here
For Genymotion, the address is 10.0.3.2
. More info here