okhttp3

Java - Retrieving Result from OkHttp Asynchronous GET

倾然丶 夕夏残阳落幕 提交于 2019-12-19 04:57:15
问题 So I have a web-app in Spring Boot, and there is a part where I make many HTTP requests to an API, and it seems to timeout if too many requests are made. I heard that switching from Synchronous to Asynchronous requests might help this issue. Using OkHttp, this is what my Synchronous GET request looks like: private JSONObject run(String url) throws Exception { Request newRequest = new Request.Builder() .url(url) .addHeader("Authorization", token) .build(); try (Response response = client

Mock server requests Android Espresso UI Testing

这一生的挚爱 提交于 2019-12-19 03:38:04
问题 I am using Espresso to write UI tests for my Android application and would like to mock http requests using MockWebServer. I need to mock authentication responses and sign in the user before the tests are run. Is there a way make the app use mockwebserver so that isntead of making actual requests, I can use respontes enqueued on mockwebserver. So far I have: public class AuthenticationTest { @Rule public ActivityTestRule<Authentication> mActivityTestRule = new ActivityTestRule<>

Android java.security.cert.CertPathValidatorException: Trust anchor for certification path not found

拥有回忆 提交于 2019-12-18 11:55:25
问题 There are three hosts that an android app do the authentication and authorization. Final host is the REST API. For the first time using Oauth authentication and authorization process it works without issue. But if user kills the app after login and accessing the services provided by REST API and then again open the app, this issue arise. In this time authentication and authorization process is not happening, only the REST API. It caused to java.security.cert.CertPathValidatorException but it

MultipartBuilder can't be resolved in okhttp:3.0.0-RC1

好久不见. 提交于 2019-12-18 07:34:52
问题 I have used okhttp and It's working fine with following dependency: compile 'com.squareup.okhttp:okhttp:2.3.0' Recently I have updated with: compile 'com.squareup.okhttp3:okhttp:3.0.0-RC1' It shows error like MultipartBuilder can't be resolved. I am uploading image with my Previous Answer of Uploading File. Is there any way to achieve the same thing using okhttp:3.0.0-RC1 ? 回答1: It is called MultipartBody.Builder now. From the ChangeLog: Form and Multipart bodies are now modeled. We've

Add cookie to client request OkHttp

浪尽此生 提交于 2019-12-17 18:38:35
问题 So i started using Okhttp 3 and most of the examples on the web talk about older versions I need to add a cookie to the OkHttp client requests, how is it done with OkHttp 3? In my case i simply want to statically add it to client calls without receiving it from the server 回答1: There are 2 ways you can do this: OkHttpClient client = new OkHttpClient().newBuilder() .cookieJar(new CookieJar() { @Override public void saveFromResponse(HttpUrl url, List<Cookie> cookies) { } @Override public List

Automatic cookie handling with OkHttp 3

血红的双手。 提交于 2019-12-17 05:41:25
问题 I am using okhttp 3.0.1. Every where I am getting example for cookie handling that is with okhttp2 OkHttpClient client = new OkHttpClient(); CookieManager cookieManager = new CookieManager(); cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL); client.setCookieHandler(cookieManager); Can please some one guide me how to use in version 3. setCookieHandler method is not present in the version 3. 回答1: right now I'm playing with it. try PersistentCookieStore, add gradle dependencies for

OKHttp cache with expiration

佐手、 提交于 2019-12-14 03:07:23
问题 I am new to OkHttpClient and i don't know how to store cache for only 1 week. So when agent update data, it will update in mobile too after 1 week. 回答1: You can use MaxAge and MaxStale parameter of CacheControl MaxAge Sets the maximum age of a cached response. If the cache response's age exceeds MaxAge it will not be used and a network request will be made MaxStale Accept cached responses that have exceeded their freshness lifetime by up to MaxStale . If unspecified, stale cache responses

How to disable okhttp3.internal.platform.Platform log from printing on my console while executing the watson assistant's functionalities using java?

天大地大妈咪最大 提交于 2019-12-14 02:12:25
问题 I want only the output not that logs printing on my console. 来源: https://stackoverflow.com/questions/51894551/how-to-disable-okhttp3-internal-platform-platform-log-from-printing-on-my-consol

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 with Retrofit 2.0 and okhttp3

笑着哭i 提交于 2019-12-13 12:22:10
问题 I'm trying to implement caching using Retrofit and OkHttp. Here what I've already done: private static final Interceptor REWRITE_CACHE_CONTROL_INTERCEPTOR = new Interceptor() { @Override public Response intercept(Interceptor.Chain chain) throws IOException { Request originalRequest = chain.request(); Request.Builder request = originalRequest.newBuilder(); Response response = chain.proceed(request.build()); return response.newBuilder() .removeHeader("Pragma") .removeHeader("Cache-Control")