美文网首页
Android xUtils Get方法带Token访问Spri

Android xUtils Get方法带Token访问Spri

作者: fireflower2009 | 来源:发表于2020-01-21 14:47 被阅读0次

    用SpringBoot设计的后台要求Authorization带Token访问,用xUtils怎么访问呢:

    
    public void clickCardList(View view) {
    
    RequestParams params =new RequestParams("http://192.168.1.89:8085/cart/list");
    
        params.setConnectTimeout(30000);
    
        params.setMaxRetryCount(3);
    
        SharedPreferences sp = getSharedPreferences("config" , 0);
    
        String token = sp.getString("token", "");
    
        params.addHeader("Authorization", "Bearer " + token);
    
        params.setAsJsonContent(false);
    
        x.http().get(params, new Callback.CommonCallback() {
    
    @Override
    
            public void onSuccess(String result) {
    
    System.out.println("返回结果 == " + result);
    
                JSONObject jsonObject =null;
    
                try {
    
    jsonObject =new JSONObject(result);
    
                }catch (JSONException e) {
    
    e.printStackTrace();
    
                }
    
    }
    
    @Override
    
            public void onError(Throwable ex, boolean isOnCallback) {
    
    if (ex.getMessage().toString().equals("Network is unreachable")) {
    
    }
    
    System.out.println("onError" + ex.toString());
    
            }
    
    @Override
    
            public void onCancelled(CancelledException cex) {
    
    System.out.println("onCancelled");
    
            }
    
    @Override
    
            public void onFinished() {
    
    System.out.println("onFinished");
    
            }
    
    });
    
    }
    
    

    相关文章

      网友评论

          本文标题:Android xUtils Get方法带Token访问Spri

          本文链接:https://www.haomeiwen.com/subject/wzjezctx.html