Android Asynctask addheader

时间:2016-12-22 13:26:02

标签: android android-asynctask

我正在尝试连接我的webservice restful以登录用户。

我这样做:

  private class LoginTask extends AsyncTask {
       OkHttpClient client = new OkHttpClient();
        String base64NamePass;

        public LoginTask(String base64NamePass){
            this.base64NamePass = base64NamePass;
        }
        @Override
        protected Object doInBackground(Object[] params) {
            Response response = null;
            try {
               response =  get("http://192.168.0.27:8080/ServicioRestTFG/rest/UsuariosServicesRs/login", base64NamePass);
            } catch (IOException e) {
                e.printStackTrace();
            }
            return response;
        }

        private Response get (String url, String base64NamePass) throws IOException {
            Request request = new Request.Builder()
                    .get()
                    .url(url)
                    .addHeader("Authorization", base64NamePass)
                    .build();
            return client.newCall(request).execute();
        }
    }

首先,我使用base64编码用户和传递,然后将其发送到我的服务器。

但是当我添加标题时:

Request request = new Request.Builder()
                        .get()
                        .url(url)
                        .addHeader("Authorization", base64NamePass)
                        .build();
                return client.newCall(request).execute();

app forceclosed并没有告诉我错误是什么,只是关闭。

有什么想法吗?

感谢

0 个答案:

没有答案