Android - Failed to connect to rest API - Bad Request

ZookKep :

I'm trying to connect my android app with an API that runs on my PC.

I'm testing the app on my actual phone. The base URL is http://localhost:5000/api/.

object RequestManager {
    val interceptor = HttpLoggingInterceptor()
    val client = OkHttpClient.Builder().addInterceptor(interceptor).build()


    init {
        //TODO must be None at live
        interceptor.level = HttpLoggingInterceptor.Level.BODY
    }


    val retrofit = Retrofit.Builder()
        .baseUrl("http://localhost:5000/energy/api/")
        .addConverterFactory(GsonConverterFactory.create())
        .client(client)
        .build()

    val service = retrofit.create(Api::class.java)

}

I tried to go with http://< myIP >:5000/energy/api/ but I get a bad request message.

>   D/OkHttp: <-- 400 Bad Request

Any help?

Littlish :

Try using ngrok. Could be solution to your problem as you insert localhost and port and it gives you a URL to work with.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=174172&siteId=1