Reputation: 11744
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?
URL is $it
gets invoked with proper localhost
base URL and able to access the localhost
from external browser. This means server is up and runningResponse is null
is getting printed, which is kinda expectedUpvotes: 1
Views: 75
Reputation: 11744
The device had the proxy turned on (Charles). Turning that off fixed the issue.
Upvotes: 1