org.apache.http.conn.HttpHostConnectException: Connection to http://localhost refused in android
if you are using emulator to run your app for local server. mention the local ip
as 10.0.2.2
and have to give Internet permission into your app :
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.INTERNET"/>
add this tag above into AndroidManifest.xml of your Android project,and it will be ok.
http://localhost
The above host is already occupied by the emulator in which you are running the code. If you want to access the local host of your computer than use the IP Address as http://10.0.2.2:8080/
.
For more details, please refer this link.