4

I have post request like below, Cant we make it automatic like Retrofit 2.0 interceptor if access token expires get refresh token and service call continues? without interruption?

URL url = new URL(myurl + "?access_token=" + access_token);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(100000000 /* milliseconds */);
conn.setConnectTimeout(150000000 /* milliseconds */);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
conn.setRequestProperty("charset", "utf-8");
conn.setDoInput(true);
conn.connect();

Is there any method to do this automatically when we get 401 response code ?

K Neeraj Lal
  • 6,768
  • 3
  • 24
  • 33
Supz
  • 145
  • 1
  • 11
  • Yes, you can achieve it manually by your own way. Once you make a request for serviceCall then there you get access token expires then at the same time you can request for access token and on the success of that make request for previous whatever you had done at last. – Ready Android Jan 12 '17 at 05:27

1 Answers1

0

As far as i know, No way is provided for this in any framework as this is purely requirement based. You will have to post SERIAL calls as stated below :

  1. Post Main Call with Access Token; Iff successful than Stop Else go to Step2
  2. Post Call for New Access Token with Refresh Token, If Successful Update access token and again Post Main call like step 1 with updated Access token.
  3. Same way if your refresh token can expire, than handle that in same SERIAL Way.

Hope it helps a bit.

K Neeraj Lal
  • 6,768
  • 3
  • 24
  • 33
Tarun Deep Attri
  • 8,174
  • 8
  • 41
  • 56