okhttp

Okhttp refresh expired token when multiple requests are sent to the server

試著忘記壹切 提交于 2020-01-22 04:30:45
问题 I have a ViewPager and three webservice calls are made when ViewPager is loaded simultaneously. When first one returns 401, Authenticator is called and I refresh the token inside Authenticator , but remaining 2 requests are already sent to the server with old refresh token and fails with 498 which is captured in Interceptor and app is logged out. This is not the ideal behaviour I would expect. I would like to keep the 2nd and 3rd request in the queue and when the token is refreshed, retry the

Why is this skipping the onResponse method?

為{幸葍}努か 提交于 2020-01-17 05:39:25
问题 I want to get data from JSON and then return it in an array, but the array always return with null, because my program won't go into the onResponse method. I want to show this data in a RecyclerView. At first it worked but now it won't work I don't know why... private SzabadEuMusorok[] getSzabadEuMusoroks(){ if (isNetworkAvaible()){ OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder().url("validurl").build(); Call call = client.newCall(request); call.enqueue(new

Retrofit Query Annotation Without Ampersand

风格不统一 提交于 2020-01-17 05:28:10
问题 I am trying to make an API call to a mobile backend with Retrofit 2.0. In my API call, i have to make necessary call to this URL https://api.backendless.com/v1/data/Users?where=followings.objectId=%270B3BA7F9-260F-B378-FF9A-3C2448B8A700%27 To form this URL in Retrofit i have been using below interface @GET("Users?where=") Call<List<User>> getFollowers(@Query("followings.objectId") String objectId); This interface call puts an ampersand before the query parameters and generates a URL like

Using okhttp Interceptor to check the network connectitivty

試著忘記壹切 提交于 2020-01-16 06:18:12
问题 Could we use Interceptor to check the network connectivity and proceed if only it's connected? NOTICE: I'm talking about how to use okhttp interceptors to unify the network connectivity checking. 回答1: You can use a BroadcastReceiver to make your application be notified when there is a change in internet connectivity. Manifest: <receiver android:name="com.example.app.ConnectivityChangeReceiver"> <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> </intent-filter> <

Using okhttp Interceptor to check the network connectitivty

心已入冬 提交于 2020-01-16 06:14:20
问题 Could we use Interceptor to check the network connectivity and proceed if only it's connected? NOTICE: I'm talking about how to use okhttp interceptors to unify the network connectivity checking. 回答1: You can use a BroadcastReceiver to make your application be notified when there is a change in internet connectivity. Manifest: <receiver android:name="com.example.app.ConnectivityChangeReceiver"> <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> </intent-filter> <

okhttp3 : unable to create new native thread

只愿长相守 提交于 2020-01-15 11:06:24
问题 Encountered a strange problem, I couldn't reproduce it after some attempts. How to reproduce it and why it happend? It's a non-concurrent task, Call the HTTP connection in a loop. public static Response syncGet(URL url) throws IOException { log.debug("http url:{}", url); OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(15L, TimeUnit.SECONDS) .readTimeout(30L, TimeUnit.SECONDS).build(); Request request = new Request.Builder().url(url).get().addHeader("cache-control", "no

okhttp3 : unable to create new native thread

旧街凉风 提交于 2020-01-15 11:06:05
问题 Encountered a strange problem, I couldn't reproduce it after some attempts. How to reproduce it and why it happend? It's a non-concurrent task, Call the HTTP connection in a loop. public static Response syncGet(URL url) throws IOException { log.debug("http url:{}", url); OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(15L, TimeUnit.SECONDS) .readTimeout(30L, TimeUnit.SECONDS).build(); Request request = new Request.Builder().url(url).get().addHeader("cache-control", "no

FATAL EXCEPTION: OkHttp Dispatcher

烂漫一生 提交于 2020-01-13 11:37:12
问题 I'm using the OkHttp library in my android app to make web requests to a weather API. I've already implemented my code and I'm getting a FATAL EXCEPTION when doing the request. I've already added INTERNET permissions in my manifest too. MainActivity.java: private CurrentWeather currentWeather; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final ActivityMainBinding binding = DataBindingUtil.setContentView(MainActivity.this, R.layout.activity

How to enable TLSv1.3 for OkHttp 3.12.x on Android 8/9?

六月ゝ 毕业季﹏ 提交于 2020-01-13 09:37:10
问题 I'm using OkHttp 3.12.2 on Android 9 (Pixel 2 device) and try to connect to an nginx 1.14.0 running with OpenSSL 1.1.1. The nginx is capable of TLSv1.3, I verified this with Firefox 66.0.2 on Ubuntu 18.04, Chrome 73.0 on Android 9 and ChromeOS 72.0. However, OkHttp always negotiates TLSv1.2 . I also tried to set a RESTRICTED_TLS ConnectionSpec, but it didn't help. I did not find a specific instruction on how to get TLSv1.3 working on Android. I know that only Android 8 and 9 support TLSv1.3

Handling Authentication in Okhttp

本秂侑毒 提交于 2020-01-12 01:58:33
问题 I'm using OkHttp 2.3 with basic authentication requests, according to OKHttp docs, it automatically retries unauthenticated requests, but whenever I provide invalid credentials, the request takes too much time and I get this exception in the end: java.net.ProtocolException: Too many follow-up requests: 21 How can I prevent OkHttp from automatically retrying unauthenticated requests, and return 401 Unauthorized instead? 回答1: protected Authenticator getBasicAuth(final String username, final