theapache64
theapache64

Reputation: 11744

OkHttp MockWebServer dispatch not getting triggered

Here's my code in isolation

fun getMockServerUrl(): String {
    val server = MockWebServer()
    server.dispatcher = object : Dispatcher() {
        override fun dispatch(request: RecordedRequest): MockResponse {
            println("dispatch hit 🚀")
            TODO()
        }
    }
    server.start()
    val url = server.url(path = "")

    val api = Retrofit.Builder()
        .baseUrl(url)
        ...
        .create(MyApi::class.java)

    Thread {
        api.getData().enqueue(
            object : Callback<String> {
                override fun onResponse(call: Call<String>, response: Response<String>) {
                    println("Response is ${response.body()}")
                }
            },
        )
    }.start()
    

    return url.toString().also {
        println("URL is $it")
    }
}

What's happening?

Upvotes: 1

Views: 75

Answers (1)

theapache64
theapache64

Reputation: 11744

The device had the proxy turned on (Charles). Turning that off fixed the issue.

Upvotes: 1

Related Questions