okhttp

kotlin/TypeCastException when trying to create OkHttpClient object

与世无争的帅哥 提交于 2019-12-21 07:55:52
问题 When i try to create a new OkHttpClient object an Exception get thrown I'm using OkHttp 3.11.0 and OkIO 2.0.0-RC1. Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/TypeCastException at okhttp3.ResponseBody.create(ResponseBody.java:210) at okhttp3.internal.Util.(Util.java:60) at okhttp3.OkHttpClient.(OkHttpClient.java:123) at p12.Main.main(Main.java:8) Caused by: java.lang.ClassNotFoundException: kotlin.TypeCastException at java.net.URLClassLoader.findClass(URLClassLoader.java

retrofit + okhttp : Retrieve GZIPInputStream

╄→гoц情女王★ 提交于 2019-12-21 07:27:33
问题 I have a problem when i activate gzip on WS using retrofit 1.4.1 and okhttp 1.3.0. RequestInterceptor requestInterceptor = new RequestInterceptor() { @Override public void intercept(RequestFacade request) { request.addHeader("content-type", "application/json"); request.addHeader("accept-encoding", "gzip"); // Here is the problem } }; RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint(Constants.HOST) .setLogLevel(RestAdapter.LogLevel.FULL) .setRequestInterceptor

Retrofit add header with token and id

Deadly 提交于 2019-12-21 05:12:17
问题 I have a problem with getting authenticated user. Before it I got token and user id. Now i need to get user from server using access token and id. I have header format Now I'am trying to add header with user token and id using interceptor. My code: Interceptor interceptor = new Interceptor() { @Override public okhttp3.Response intercept(Chain chain) throws IOException { Request newRequest = chain.request().newBuilder() .addHeader("Accept", "application/json") .addHeader("authorization", token

Getting Request body content using Retrofit 2.0 POST method

一曲冷凌霜 提交于 2019-12-21 03:55:06
问题 I have a requirement to get a request body and to perform some logic operations with Retrofit 2.0 before doing enque operation. But unfortunately I am not able to get the post body content from my service call. At present after searching a lot I found only one solution like logging the request that I am posting using Retrofit 2.0 from this method by using HttpLoggingInterceptor with OkHttpClient . I am using the following code to log the request body in the Android Logcat:

InterruptedIOException while using Retrofit2 with rx when retryOn

喜你入骨 提交于 2019-12-20 23:20:10
问题 I'm using retrofit 2 with rx-android I have quite complex retry logic, which partially works . I cut off irrelevant code to simplify it. Here it is: public class RetryWithDelay implements Func1<Observable<? extends Throwable>, Observable<?>>, Constants { @Override public Observable<?> call(Observable<? extends Throwable> attempts) { return attempts.flatMap(new Func1<Throwable, Observable<?>>() { @Override public Observable<?> call(Throwable throwable) { int statusCode = 500; if (throwable

Detect if OkHttp response comes from cache (with Retrofit)

那年仲夏 提交于 2019-12-20 17:41:32
问题 Is there a way to detect if a Retrofit response comes from the configured OkHttp cache or is a live response? Client definition: Cache cache = new Cache(getCacheDirectory(context), 1024 * 1024 * 10); OkHttpClient okHttpClient = new OkHttpClient.Builder() .cache(cache) .build(); Api definition: @GET("/object") Observable<Result<SomeObject>> getSomeObject(); Example call: RetroApi retroApi = new Retrofit.Builder() .client(okHttpClient) .baseUrl(baseUrl) .addCallAdapterFactory

How to get response body to retrofit exception?

廉价感情. 提交于 2019-12-20 09:14:09
问题 I am trying to connect to rest service via retrofit in android application. I am getting responses. But when there is some error response from the service, conversion exception occurs and now I want to do some actions based on the response body. But I am getting response body as NULL. But retrofit log has a error message. Why is this happening. D/Reftofit log(24856): OkHttp-Received-Millis: 1397527055676 D/Reftofit log(24856): OkHttp-Response-Source: NETWORK 200 D/Reftofit log(24856): OkHttp

Download progress with RxJava, OkHttp and Okio in Android

丶灬走出姿态 提交于 2019-12-20 08:49:38
问题 In our app I download an image file with this code. I need to show download progress( downloaded bytes in percentage ) on UI. How I can get download progress in this code? I searched for solution, but still can't manage to do it on my own. Observable<String> downloadObservable = Observable.create( sub -> { Request request = new Request.Builder() .url(media.getMediaUrl()) .build(); Response response = null; try { response = http_client.newCall(request).execute(); if (response.isSuccessful()) {

Square`s OkHttp. Download progress

孤街醉人 提交于 2019-12-20 08:40:36
问题 Is there any way to get downloading file progress when using square`s OkHttp? I did not find any solution in Recipes. They have class Call which can get content asynchronically, but there is no method to get current progress. 回答1: Oops answer was obvious. Sorry for dumb question. Just need to read InputStream as usual. private class AsyncDownloader extends AsyncTask<Void, Long, Boolean> { private final String URL = "file_url"; @Override protected Boolean doInBackground(Void... params) {

Android OkHttp, refresh expired token

安稳与你 提交于 2019-12-20 08:39:02
问题 Scenario : I am using OkHttp / Retrofit to access a web service: multiple HTTP requests are sent out at the same time. At some point the auth token expires, and multiple requests will get a 401 response. Issue : In my first implementation I use an interceptor (here simplified) and each thread tries to refresh the token. This leads to a mess. public class SignedRequestInterceptor implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { Request request =