okhttp3

Alternative to sslSocketFactory in Java10

回眸只為那壹抹淺笑 提交于 2020-08-19 07:31:27
问题 I am using OkHttp and I need to ignore SSL errors for application debugging. This used to work in Java 8. final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { @Override public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { } @Override public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { } @Override public java.security.cert

Getting an error Using 'body(): ResponseBody?' is an error. moved to val with okhttp

久未见 提交于 2020-06-13 19:24:07
问题 Using response.body() gives me an error of "Using 'body(): ResponseBody?' is an error. moved to val" i tried removing ? but nothing works the error is in body() override fun onResponse(call: Call, response: Response) { val body = response.body()?.string(); println(body) println("Sucees") 回答1: It looks like you're using OkHttp 4.0.0. The response.body() function has been deprecated. Instead, you need to access the body as a val, like this: override fun onResponse(call: Call, response: Response

mocking Retrofit response calls with Call not working

北城余情 提交于 2020-05-26 10:25:07
问题 I'm mocking the response of the APIService. Unfortunately it is not working, I have to send back a Call but I don't understand how. The question is how to send back a Call object. @RunWith(AndroidJUnit4::class) class ApiServiceTest { @Test fun testSomething() { val apiService = ApiServiceMock() val call = apiService.getStep1User() val result = call.execute() Assert.assertEquals("SomeUserValue", result.body()!!.getResponse()) } } Here is the mocked service: class ApiServiceMock : ApiService {

Firebase isn't reporting crashes related to OkHttp

对着背影说爱祢 提交于 2020-05-26 10:19:12
问题 I was migrating my code from Google analytics to Firebase, following problem I'm facing Some of the custom events show correct value while others not although code used are same in all cases. Can provide code if required. Update : Above is solved, I was sending large data so its just omitted them. Prior to using OkHttp(using Android network library and Asynctask) firebase shows correct line number in crash reports but not after using OkHttp, I can confirm that I have uploaded correct mapping

okhttp get failure response

☆樱花仙子☆ 提交于 2020-04-09 18:27:37
问题 I've implemented okhttp in my android client for network calls. When i get a failure response i get the failure code and the text related to the code as a message but i don't get the custom failure response that the server sends me. In my failure response in the implemented code the message i get is just "Bad Request". Whereas the same response from the browser is as follows. How do i get the error message the server is giving me back? My code private void executeCall(Request request, final

How to add Api_KEY into interceptor using okhttp

让人想犯罪 __ 提交于 2020-02-24 06:56:24
问题 I have this service where I want to put the token as an interception in the okhttp instead of passing as a parameter with @Header("MY_API_KEY") This is my code regarding the service /** * Provides the [PHService] */ fun provideService(): PHService { val logger = HttpLoggingInterceptor() logger.level = HttpLoggingInterceptor.Level.BASIC val client = OkHttpClient.Builder() .addInterceptor(logger) .build() return Retrofit.Builder() .baseUrl(BuildConfig.API_URL) .client(client)

How to add Api_KEY into interceptor using okhttp

馋奶兔 提交于 2020-02-24 06:56:02
问题 I have this service where I want to put the token as an interception in the okhttp instead of passing as a parameter with @Header("MY_API_KEY") This is my code regarding the service /** * Provides the [PHService] */ fun provideService(): PHService { val logger = HttpLoggingInterceptor() logger.level = HttpLoggingInterceptor.Level.BASIC val client = OkHttpClient.Builder() .addInterceptor(logger) .build() return Retrofit.Builder() .baseUrl(BuildConfig.API_URL) .client(client)

How to add Api_KEY into interceptor using okhttp

為{幸葍}努か 提交于 2020-02-24 06:55:00
问题 I have this service where I want to put the token as an interception in the okhttp instead of passing as a parameter with @Header("MY_API_KEY") This is my code regarding the service /** * Provides the [PHService] */ fun provideService(): PHService { val logger = HttpLoggingInterceptor() logger.level = HttpLoggingInterceptor.Level.BASIC val client = OkHttpClient.Builder() .addInterceptor(logger) .build() return Retrofit.Builder() .baseUrl(BuildConfig.API_URL) .client(client)

OkHttp 3.11 and TLS 1.2 support

生来就可爱ヽ(ⅴ<●) 提交于 2020-02-22 07:18:25
问题 The support for TLS v1.2 was added in Android 4.2, but it wasn't enabled by default. This issue was quite easy to fix with OkHttp 3.x by providing a custom SSLSocketFactory implementation to the OkHttp client: OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.setSocketFactory(new MySSLSocketFactory()); In my case the custom socket factory was setting the enabled protocols like this: private static final String[] TLS_PROTOCOLS = new String[]{ "TLSv1.1", "TLSv1.2" }; public