okhttp

Retrofit Offline cashing returns a null response.body()

你离开我真会死。 提交于 2019-12-02 02:58:37
I tried this link and this link to construct an offline Retrofit cache. The problem is that if I put the phone in Airplane mode, the Response.body() is always null. Here's my code: OkHttpClient client = new OkHttpClient .Builder() .cache(new Cache(App.sApp.getCacheDir(), 10 * 1024 * 1024)) // 10 MB .addInterceptor(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Request request = chain.request(); if (App.isNetworkAvailable()) { request = request.newBuilder().header("Cache-Control", "public, max-age=" + 60).build(); } else { request = request.newBuilder(

CompositeDisposable.clear causes OkHttp to throw java.lang.IllegalStateException: Unbalanced enter/exit

℡╲_俬逩灬. 提交于 2019-12-01 21:30:33
So I have a simple http request using OkHttp. I do this with RxJava on Android. I add this RxJava call to a CompositeDisposable that I then clear on onStop . For some reason that is triggering this exception below. I'm a little unsure about how to fix it. Caused by java.lang.IllegalStateException: Unbalanced enter/exit at okio.AsyncTimeout.enter(AsyncTimeout.java:73) at okio.AsyncTimeout$2.read(AsyncTimeout.java:235) at okio.RealBufferedSource.read(RealBufferedSource.java:47) at okhttp3.internal.http1.Http1Codec$AbstractSource.read(Http1Codec.java:363) at okhttp3.internal.http1.Http1Codec

What is the difference between the OkHttp methods .toString() and .string()?

若如初见. 提交于 2019-12-01 18:56:01
I have a snippet of code: override fun onResponse(call: Call<ResponseBody>, response: Response<ResponseBody>) { try { Log.d("DEBUG POST=====>", response.body()!!.string()) }catch(e:IOException) { e.printStackTrace() } } When I use response.body()!!.string() I get the correct output, and JSON body. When I use: response.body().toString() I get okhttp3.ResponseBody$1@c626d25 Can anyone kindly tell me what is the difference between the two methods? Zoe the transgirl string() isn't a valid Kotlin (or Java) method, as in neither of the languages define it. It's defined by OkHttp in ResponseBody and

POST Streaming Audio over HTTP/2 in Android

家住魔仙堡 提交于 2019-12-01 18:35:40
Some background: I am trying to develop a voice-related feature on the android app where a user can search using voice and the server sends intermediate results while user is speaking (which in turn updates the UI) and the final result when the query is complete. Since the server accepts only HTTP/2 single socket connection and Android HTTPUrlConnection doesn't support HTTP/2 yet, I am using Retrofit2. I have looked at this , this and this but each example has fixed length data or the size can be determined beforehand... which is not the case for audio search. Here's what my method for POST

Retrofit Closing Response Body

别说谁变了你拦得住时间么 提交于 2019-12-01 17:40:35
I've been getting this error: A connection to ****** was leaked. Did you forget to close a response body? So I went on and close the responses I get. response.body().close() Problem is if the response.body() is already converted to a custom class, there's no close method available. Also I tried calling raw and gives me an exception: fetchSomething.enqueue(new Callback<SomethingClass>() { @Override public void onResponse(Call<SomethingClass> call, Response<SomethingClass> response) { //Closes the response body response.raw().body().close(); //<--- gives illegalStateException } @Override public

No class found exception com.squareup.okhttp.logging.HttpLoggingInterceptor

↘锁芯ラ 提交于 2019-12-01 17:29:44
Even after adding the dependencies and importing the class I am getting java.lang.NoClassDefFoundError: com.squareup.okhttp.logging.HttpLoggingInterceptor. Can anyone please help? Gradle Build file apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "xyz" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" multiDexEnabled = true } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } repositories { mavenCentral() } }

Retrofit invokes failure() method even when the headers status code is 200

假装没事ソ 提交于 2019-12-01 16:34:49
I am using retrofit for my backend communication and below it the snippet of my retrofit call: serverObject.createEvent(Utils.getAuthHeader(), params, new Callback<CreateEventResponse>() { @Override public void success(CreateEventResponse outputObj, retrofit.client.Response response) { Log.d(TAG, outputObj.getTitle() + " is successfully created."); setResult(Activity.RESULT_OK); finish(); } @Override public void failure(RetrofitError retrofitError) { //Header status code Log.e("failure", String.valueOf(retrofitError.getResponse().getStatus())); Log.e("failure", String.valueOf(retrofitError

No class found exception com.squareup.okhttp.logging.HttpLoggingInterceptor

左心房为你撑大大i 提交于 2019-12-01 15:50:18
问题 Even after adding the dependencies and importing the class I am getting java.lang.NoClassDefFoundError: com.squareup.okhttp.logging.HttpLoggingInterceptor. Can anyone please help? Gradle Build file apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "xyz" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" multiDexEnabled = true } buildTypes { release { minifyEnabled false proguardFiles

Retrofit invokes failure() method even when the headers status code is 200

我与影子孤独终老i 提交于 2019-12-01 15:48:41
问题 I am using retrofit for my backend communication and below it the snippet of my retrofit call: serverObject.createEvent(Utils.getAuthHeader(), params, new Callback<CreateEventResponse>() { @Override public void success(CreateEventResponse outputObj, retrofit.client.Response response) { Log.d(TAG, outputObj.getTitle() + " is successfully created."); setResult(Activity.RESULT_OK); finish(); } @Override public void failure(RetrofitError retrofitError) { //Header status code Log.e("failure",

Retrofit Closing Response Body

守給你的承諾、 提交于 2019-12-01 15:44:22
问题 I've been getting this error: A connection to ****** was leaked. Did you forget to close a response body? So I went on and close the responses I get. response.body().close() Problem is if the response.body() is already converted to a custom class, there's no close method available. Also I tried calling raw and gives me an exception: fetchSomething.enqueue(new Callback<SomethingClass>() { @Override public void onResponse(Call<SomethingClass> call, Response<SomethingClass> response) { //Closes