I was trying to connect to android emulator on localhost and i'm getting the following error
onFailure: java.net.ConnectException: Failed to connect to /127.0.0.1:3000
Any help would be greatly appreciated thanks in advance.
Here is the code i'm trying to run
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
call()
}
private fun call() {
val retrofit = Retrofit.Builder()
.baseUrl("http://127.0.0.1:3000")
.addConverterFactory(GsonConverterFactory.create())
.build()
val apiService = retrofit.create(ApiService::class.java)
val call = apiService.login()
call.enqueue(object : Callback<String>{
override fun onResponse(call: Call<String>, response: Response<String>) {
Log.i("api_test", "onSuccess: ${response.body()}")
}
override fun onFailure(call: Call<String>, t: Throwable) {
Log.i("api_test", "onFailure: $t")
}
})
}
}
interface ApiService {
@GET("test")
fun login(): Call<String>
}