With a new version of okhttp(4.9.0, not sure if it was in lower versions) and Retrofit 2.9.0(also lower versions). I started to see in firebase and google analytics reports about UnknownHostException. I tried to repro this crash and found that it is happening when the internet is off or very low quality. I call addInterceptor in the framework layer and
Tag: okhttp
The speed does not change from an asynchronous request
I need to make about 60 HTTP requests. In the first case, I did not use an asynchronous request and the speed was about 1.5 minutes. In the second case, I used an asynchronous request and the speed did not change either and was about 1.5 minutes. Please see my code. Maybe I’m not doing the asynchronous request correctly or
List All Data Using Retrofit/OkHttp With Response List
I have some codes that fetch some data from my API. My question is how can I list all the objects that I fetched before without using this jsonData.get(0), I expect something like jsonData.get(i), so …
FATAL EXCEPTION: OkHttp Dispatcher
I’m using the OkHttp library in my android app to make web requests to a weather API. I’ve already implemented my code and I’m getting a FATAL EXCEPTION when doing the request. I’ve already added INTERNET permissions in my manifest too. MainActivity.java: Gradle: Then, here’s the exception I’m getting: I don’t know what to do at this point. I’ve read
Request working fine in postman, but getting a 403 in OkHTTP
I’m trying to make a request to the Genius API, but I’m running into some issues using OkHTTP. This is my small script I’m using to make the call: When I run this script, I get a 403 error: For reference, here is a picture of me making the same exact request with Postman, and it works: Any ideas on
why use Retrofit when we have OkHttp
with OkHttp we can make HTTP request then get response from server then with Gson lib convert response to object we need. this is from Square/OkHttp doc: Its request/response API is designed with fluent builders and immutability. It supports both synchronous blocking calls and async calls with callbacks I read from stackOverFlow Retrofit uses OkHTTP automatically if available . So
Logging with Retrofit 2
I’m trying to get the exact JSON that is being sent in the request. Here is my code: But I only see this in the logs: How am I supposed to do proper logging, given the removal of setLog() and setLogLevel() which we used to use with Retrofit 1? Answer In Retrofit 2 you should use HttpLoggingInterceptor. Add dependency to
Can’t get OkHttp’s response.body.toString() to return a string
I’m trying to get some json data using OkHttp and can’t figure out why when i try logging the response.body().toString() what i get is Results:﹕ com.squareup.okhttp.Call$RealResponseBody@41c16aa8 I don’t know what i’m doing wrong here. How do i get the response string? Answer Just in case someone bumps into the same weird thing as I have. I run my code during