Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1.  public void getToken(){
  2.  
  3.     Thread thread = new Thread(new Runnable()
  4.     {
  5.         @Override
  6.         public void run()
  7.         {
  8.             try
  9.             {
  10.                 Request request = new Request.Builder()
  11.                         .url(Constants.TOKEN_URL)
  12.                         .build();
  13.  
  14.                 Response response = client.newCall(request).execute();
  15.                 if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  16.  
  17.                 Headers responseHeaders = response.headers();
  18.  
  19.                 for (int i = 0; i < responseHeaders.size(); i++) {
  20.  
  21.                     if (responseHeaders.value(i).startsWith(Constants.TOKEN_HEADER)) {
  22.  
  23.                         String cookies = responseHeaders.value(i);
  24.                         String CookieValue = null;
  25.  
  26.                         if(cookies != null){
  27.                             String[] temp=cookies.split(";");
  28.                             for (String ar1 : temp ){
  29.                                 if(ar1.contains(Constants.TOKEN_HEADER)){
  30.                                     String[] temp1=ar1.split("=");
  31.                                     CookieValue = temp1[1];
  32.                                 }
  33.                             }
  34.                         }
  35.  
  36.                         Log.e("Token:", CookieValue);
  37.                         String token = CookieValue;
  38.  
  39.                     }
  40.  
  41.                 }
  42.  
  43.             }
  44.             catch (Exception e)
  45.             {
  46.                 e.printStackTrace();
  47.             }
  48.         }
  49.     });
  50.  
  51.     thread.start();
  52.  
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement