At first, I guess you are running your application on an emulator so actually the localhost
now pointing to you emulator which is not the server. Therefore, the connection can't be established and cause the error.
Instead of using localhost
or 127.0.0.1
as your server address, try using your PC IP as the server address, you can find the IP on the cmd with the command: ipconfig /all
Hope this help.