okhttp3

OkHttpClient throws exception after upgrading to OkHttp3

喜夏-厌秋 提交于 2019-11-30 01:27:38
I'm using following lines of code to add a default header to all of my requests sent using Retrofit2: private static OkHttpClient defaultHttpClient = new OkHttpClient(); static { defaultHttpClient.networkInterceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Request request = chain.request().newBuilder() .addHeader("Accept", "Application/JSON").build(); return chain.proceed(request); } }); } After upgrading retrofit to beta-3 version, I had to upgrade OkHttp to OkHttp3 also (actually I just changed package names from okhttp to okhttp3, the

Retrofit API call receives “HTTP FAILED: java.io.IOException: Canceled”

*爱你&永不变心* 提交于 2019-11-30 00:21:16
问题 Can't figure out why is this happening. Neither one of rx callbacks (onCompleted(), onError(), onNext()) not gets triggered by my call. The only thing i receive is this okhttp output: D/OkHttp: --> GET https://api.privatbank.ua/p24api/exchange_rates?json=true&date=20.11.2016 http/1.1 D/OkHttp: --> END GET D/OkHttp: <-- HTTP FAILED: java.io.IOException: Canceled Retrofit module: @Module public class RestModule { @Provides @Singleton public HttpLoggingInterceptor providesHttpLogginInterceptor()

How can I make a simple HTTP request in MainActivity.java? (Android Studio)

本小妞迷上赌 提交于 2019-11-29 15:25:51
问题 I'm using Android Studio, and I've spent a few hours trying to do a simple HTTP request in my MainActivity.java file, and tried multiple ways, and seen many web pages on the subject, yet cannot figure it out. When I try OkHttp, I get a error about not being able to do it on the main thread. Now I'm trying to do it this way: public static String getUrlContent(String sUrl) throws Exception { URL url = new URL(sUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection();

OkHttpClient cannot cancel Call by tag

不想你离开。 提交于 2019-11-29 11:22:30
I recently upgraded to OkHttp3 , and noticed that you could no longer cancel a Call by tag directly from the Client. This has to be handled by the application now. Stated in the CHANGELOG here: Canceling batches of calls is now the application's responsibility. The API to cancel calls by tag has been removed and replaced with a more general mechanism. The dispatcher now exposes all in-flight calls via its runningCalls() and queuedCalls() methods. You can write code that selects calls by tag, host, or whatever, and invokes Call.cancel() on the ones that are no longer necessary. I'm self

Connection pool and File handles

旧时模样 提交于 2019-11-29 03:59:48
问题 We use Retrofit/OkHttp3 for all network traffic from our Android application. So far everything seems to run quite smoothly. However, we have now occasionally had our app/process run out of file handles. Android allows for a max of 1024 file handles per process OkHttp will create a new thread for each async call Each thread created this way will (from our observation) be responsible for 3 new file handles (2 pipes and one socket). We were able to debug this exactly, where each dispached async

Add cookie to client request OkHttp

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 23:33:54
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 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<Cookie> loadForRequest(HttpUrl url) { final ArrayList<Cookie> oneCookie = new ArrayList<>(1); oneCookie.add

Okhttp android Websocket and Jetty Server connection with SSL

那年仲夏 提交于 2019-11-28 14:31:59
I have my okhttpclient android websocket and jetty stand-alone server given below. I have to enable strong security for the communication between the android client and jetty server. I am facing issue on client side which is given below. Server Side package com.wss.okhttp; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.Certificate; import java.security.cert.CertificateException; import java.security.cert

java.lang.NoClassDefFoundError: okhttp3.internal.Util

旧城冷巷雨未停 提交于 2019-11-28 13:08:47
[enter image description here][1] My program can run Android 5.1 phone , but the phone will not be able to run Android 4.3 , and will run out of the bottom of the error > E/AndroidRuntime: FATAL EXCEPTION: EventThread >java.lang.NoClassDefFoundError: okhttp3.internal.Util >at okhttp3.OkHttpClient.<clinit>(OkHttpClient.java:65) >at okhttp3.OkHttpClient$Builder.<init>(OkHttpClient.java:381)> at>io.socket.engineio.client.transports.WebSocket.doOpen(WebSocket.java:51) >at io.socket.engineio.client.Transport$1.run(Transport.java:75) >at io.socket.thread.EventThread.exec(EventThread.java:50) >at io

Sending JSON body through POST request in OKhttp in Android

耗尽温柔 提交于 2019-11-28 03:51:15
问题 I have setting up OkHttpClient and successfully sending the GET request to the server. And also I could able to sending the POST request to the server with empty body tag. Now, I'm trying to send the following JSON Object to the server. { "title": "Mr.", "first_name":"Nifras", "last_name": "", "email": "nfil@gmail.com", "contact_number": "75832366", "billing_address": "", "connected_via":"Application" } For this I have trying to adding the OkHttpClient library class RequestBody but I fail to

ProtocolException: Expected ':status' header not present

孤者浪人 提交于 2019-11-27 21:16:18
Retrofit network calls fails with a Protocol Exception suddenly in a working app. The app was working till yesterday and today all the network calls fails. The calls works fine with HTTP but fails with HTTPS. Here is the logs, java.net.ProtocolException: Expected ':status' header not present 10-18 14:59:01.103 30746-30746/? W/System.err: at okhttp3.internal.http.Http2xStream.readHttp2HeadersList(Http2xStream.java:262) 10-18 14:59:01.103 30746-30746/? W/System.err: at okhttp3.internal.http.Http2xStream.readResponseHeaders(Http2xStream.java:145) 10-18 14:59:01.103 30746-30746/? W/System.err: at