okhttp

Android rxjava with okhttp - NetworkOnMainThreadException

若如初见. 提交于 2019-12-12 02:32:42
问题 I sometimes get exception - android.os.NetworkOnMainThreadException, sometimes code works. Here is my code Observable.create(new Observable.OnSubscribe<Response>() { OkHttpClient client = new OkHttpClient(); @Override public void call(Subscriber<? super Response> subscriber) { try { Response response = client.newCall(request).execute(); subscriber.onNext(response); subscriber.onCompleted(); } catch (IOException e) { subscriber.onError(e); } } }).subscribeOn(Schedulers.io()) .observeOn

How to read body following an 101 response code?

落爺英雄遲暮 提交于 2019-12-11 17:56:11
问题 From the docs, immediately after sending the 101 (Switching Protocols) response, the server is expected to continue responding to the original request as if it had received its equivalent within the new protocol (i.e., the server still has an outstanding request to satisfy after the protocol has been changed, and is expected to do so without requiring the request to be repeated). If the Upgrade header field is received in a GET request and the server decides to switch protocols, it first

How to make an Okhttp Request with “Content-type:application/x-www-form-urlencoded”?

半腔热情 提交于 2019-12-11 17:49:06
问题 I have an api requirement of Sending following parameters in header- Content-Type - application/x-www-form-urlencoded authKey- (Session token) and following parameters in body(form day i.e key-value pair) storeId -1 type -Product CategoryId -324 But whenever I hit this api, I am always getting 401(UnAuthorized) error. I have tried using MultipartRequest body and formBody, I know this is nothing to do with the body(Its the header where I need to send the Content-Type and authKey). Below is my

Android Api (Okhttps) not getting called in android 9(pie) and above [duplicate]

守給你的承諾、 提交于 2019-12-11 16:23:21
问题 This question already has answers here : Volley Not making request on latest version of Android (4 answers) Closed 7 months ago . I am calling the android API in the same way as for other versions of phone and its working fine till Oreo version i.e. 8. But the API is not getting called in android 9 i.e. pie version and above. If there are some changes in pie, do let me know. Thanks in advance. private void getLoginAPI(String username, String password, String compnaycoce) { if (NetworkStatus

How do I do multiplexing on OkHttp?

可紊 提交于 2019-12-11 16:01:38
问题 I see some older questions about using SPDY (though the code has changed significantly since then), but no insights into how to properly leverage multiplexing and/or pipelining in OkHttp. I've gone through all the examples and have yet to see anything specifically referring to this. Is this something that is automatically done? 回答1: It’s automatic. If you have a server that supports HTTP/2, and a client that supports HTTP/2, it’ll do the right thing. 来源: https://stackoverflow.com/questions

Strange error with GLIDE while loading image on production build

北城以北 提交于 2019-12-11 15:48:08
问题 After applying ProGuard on my production app. We are facing the following error on loading images from URLs E/vw: Glide failed to load image with exception: UNABLE TO LOAD PUBLICSUFFIXES.GZ RESOURCE FROM THE CLASSPATH. java.lang.IllegalStateException: Unable to load publicsuffixes.gz resource from the classpath. Finally, we tried keeping the whole Glide sources in the progaurd configuration with the following command -keep public class * implements com.bumptech.glide.module.GlideModule -keep

Retrofit Observable response to LiveData object using subscribe

微笑、不失礼 提交于 2019-12-11 15:13:00
问题 I have inherited this project that was using retrofit incorrectly with LiveData by trying to convert responses to LiveData immediately. I am in the middle of trying to refactor, but am getting stuck with converting an RxJava Observable to a LiveData object in the ViewModel. Here is what I have so far: Retrofit Service interface Service { @POST("user/login") fun postLogin(@Body body: LoginBody) Observable<ApiResponseWrapper<LoginRemote>> } As you can see, Observable wraps an ApiResponseWrapper

Duplicate libraries in two different project modules

心不动则不痛 提交于 2019-12-11 10:18:33
问题 I have project with two modules. I'm using SalesforceSDK which is included as separate module and inside SalesforceSDK I have Cordova which is using okhttp . In second module I have retrofit library which is using okhttp too and when I try to build the project I get duplicate dex files error I tried to delete okhttp dependency from SalesforceSDK and include it from my second module but I'm getting symbols not found error Only thing left to do is to include okhttp as different module but

Retrofit + OkHttp + cache + HTTPS

百般思念 提交于 2019-12-11 09:59:58
问题 I have problem with Retrofit combine with OkHttp Cache and HTTPS. Simply, it doesn't work. When I switch endpoint to non-https version, everything works. My Retrofit instance: File cacheDirectory = new File(App.get().getApplicationContext() .getCacheDir().getAbsolutePath(), "HttpCache"); try { cache = new Cache(cacheDirectory, 10 * 1024 * 1024); } catch (IOException ioe) { Log.w(TAG, ioe); } OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.setCache(cache); mInstance = new

Handle timeout in OkHTTP

扶醉桌前 提交于 2019-12-11 07:59:19
问题 How can i catch the timeout in OkHTTP? Is it "called" in the onFailure method? I would like to handle the situation in which i have bad internet connection. In case of timeout i have to enable some buttons to allow the user to try again. // Get a handler that can be used to post to the main thread client.newCall(request).enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { hideDialog(); e.printStackTrace(); // handle timeouts here, enable buttons... } 回答1: You