用xutils3.0来访问 spring boot,带权限验证

 public static void postNewServer() {
        RequestParams params = new RequestParams("http://172.16.1.215:8080/api/i/users/list");
        byte[] bytes = String.format("%s:%s", "abc", "2505").getBytes();
        String aut = String.format("Basic %s", Base64Utils.encodeToString(bytes));
//        byte[] encodedPassword = (userName + ":" + password).getBytes();
//        BASE64Encoder encoder = new BASE64Encoder();
        params.addHeader("Authorization", aut);
        x.http().get(params, new Callback.CacheCallback() {

            @Override
            public void onSuccess(String result) {

                Log.d("dd", "suc");

                DbCookieStore instance = DbCookieStore.INSTANCE;
                List cookies = instance.getCookies();
                for (HttpCookie heCo : cookies
                        ) {
                    Log.d("dd", heCo.getName() + heCo.getValue());
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }

            @Override
            public boolean onCache(String result) {
                return false;
            }
        });
    }

你可能感兴趣的:(用xutils3.0来访问 spring boot,带权限验证)