Referencing "localhost" to refer to your local machine doesn't work on the Android emulator; you need to use a special IP which the emulator will forward on to the host machine. You need to replace localhost
with 10.0.2.2
, as per this answer.
If you're testing this on a physical device (rather than the emulator) you'll need to use your machines IP on the local network.