okhttp

How to wait for the result on a Okhttp call to use it on a test?

本秂侑毒 提交于 2019-12-14 01:33:48
问题 I've created a method to check if my app is able to connect to my server using OkHttp. This is my test class: public class NetworkTest { static boolean resultWeb = false; public static boolean pingTestWeb() { OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url("http://www.google.com")//My server address will go here .build(); client.newCall(request).enqueue(new Callback() { @Override public void onFailure(Request request, IOException e) { resultWeb = false;

OkHttp PublicKey pinning on Android

一个人想着一个人 提交于 2019-12-14 01:04:13
问题 Does anyone know how we could implement Public Key pinning with OkHttp3 Have been reading about SSL pinning and I see that we could do it with either Certificate Pinning or Public Key pinning (the latter seems more flexible). But I was only able to find example of Certificate pinning with OkHttp and none of Key Pinning. Does anyone know how easy this is to implement with OkHttp (and/or an example of how to go about doing so)? TIA 回答1: Been looking through the source of the CertificatePinner

Caching in Picasso

雨燕双飞 提交于 2019-12-13 21:07:58
问题 After reading several documentations, i want to clear some points Reference: this For Picasso to cache my image into memory, do i have to enable "Cache-control" header in my response? If i am using OkHttpDownloader with Picasso,will it still require me to enable the header? public Picasso getImageLoader(Context ctx) { Picasso.Builder builder = new Picasso.Builder(ctx); builder.downloader(new OkHttpDownloader(ctx) { @Override protected HttpURLConnection openConnection(Uri uri) throws

How to catch the Exception in Retrofit android

江枫思渺然 提交于 2019-12-13 20:30:46
问题 I have defined the classes as below. I have used dagger with Retrofit here What I am trying to do :: I am trying to catch the OfflineException in the request below how to catch it in Main Activity properly. RequestInterceptor.java public class RequestInterceptor implements Interceptor { ConnectivityManager connectivityManager; Application mApplication; @Inject public RequestInterceptor(Application mApplication) { this.mApplication = mApplication; connectivityManager = (ConnectivityManager)

Retrofit call to server 2.0.0Beta2, nothing happening - callback never invoked

我们两清 提交于 2019-12-13 06:17:11
问题 I make the call like such: ApiInterface.getKidMixClient(getActivity()).getAccountDetails().enqueue(LoginFragment.this); Here is my interface definition: @GET(Endpoints.GET_MY_ACCOUNT_DETAILS+"/") Call<Account> getAccountDetails(); But my callback onResponse is never being invoked? Is there something wrong with this set up? public class ApiInterface { private static ApiService apiInterface; public static ApiService getKidMixClient(final Context context) { if (apiInterface == null) {

android https CertPathValidatorException: TrustAnchor found but certificate validation failed

ε祈祈猫儿з 提交于 2019-12-13 05:38:08
问题 Does anyone meet the below exception. It occurs random. After it happened, then https connection cannot be used anymore. The whole application needs to restart. The scenario : After detailed trace of the code, i updated the scenario: 1. The application has 3 process in the same application. 2. The main ui process invoke https request in another thread. 3. The another 2 processes hold the 2 servcies. one service will also invoke https request in another thread. 4. When user logout, it will

Accessing ASP.net API causes “Handshake failed” error in Android Studio

非 Y 不嫁゛ 提交于 2019-12-13 04:26:01
问题 I believe I may be missing something important, nevertheless I cannot figure out how to communicate with an API from my android project on localhost. I pretty much was following this tutorial which is outdated so I was trying to update it into current Android Studio version. However, I have arrived at an impasse, I get this Handshake failed that I cannot seem to resolve. EDIT: I'd like to note that I can access the API from a browser on the emulator and it gives the information I requested,

OkHttp not closing connection on request timeouts

穿精又带淫゛_ 提交于 2019-12-13 01:55:58
问题 I am setting readTimeout and stalling my server (Node.js + express). I am not getting a socket close from the client. Is this an expected behaviour ? 回答1: We fixed a bug related to this just yesterday. If you can do us a favor and try the latest code from git master, I'm eager to see if that fixes your problem! 来源: https://stackoverflow.com/questions/31770119/okhttp-not-closing-connection-on-request-timeouts

Save .html file into internal storage using OkHttp lib

↘锁芯ラ 提交于 2019-12-13 00:47:50
问题 I'm new to android and I'm trying to create app that save's .html page into internal storage to open it later in the WebView . I want to do that using OkHttp library but, I don't know how to do that. Maybe there is some opportunity to get code of the page in the String and store it into html? Help me please. 回答1: I am working on something similàr and this is how I saved mine. String url = "http://stackoverflow.com/questions/33056097/save-html-file-into-internal-storage-using-okhttp-lib#";

How can I set connection timeout for OkHttpClient? 2017

橙三吉。 提交于 2019-12-13 00:07:19
问题 It is easy to say it's duplicate but it isn't. I read many post about how to set the connection timeout in android but the post are 4-7 years old and I think that we all need an update about this topic because those methods are deprecated or no longer exist. So the question is how can I set my connection timeout when I am waiting for a response from the server? final Response response = httpClient.newCall(request).execute(); if (response.isSuccessful()) { //success } else { //unsuccessful }