首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将集群点数据库连接到android应用程序

如何将集群点数据库连接到android应用程序
EN

Stack Overflow用户
提问于 2015-06-11 14:48:11
回答 1查看 148关注 0票数 0

我是NoSQL数据库和云的新手。我正在尝试使用集群点(集群点)在android中开发一个简单的应用程序。我尝试并寻找了这么多的可能性,但它不是很有效。

代码语言:javascript
复制
(new AsyncTask<Void, Void, String>() {
        @Override
        protected String doInBackground(Void... params) {
      String result = "";
            try {

                String requestString = "https://username:password@api-eu" +
                        ".clusterpoint.com/908/users/";

                HttpClient httpClient = new DefaultHttpClient();
                HttpResponse httpResponse = null;
                HttpPost httpPost = new HttpPost(requestString);

                HttpResponse response = httpClient.execute(httpPost);
                HttpEntity httpEntity = response.getEntity();
                result = EntityUtils.toString(httpEntity);
            } catch (IOException e) {
                result = "Error";
                e.printStackTrace();
            } finally {
                Log.v("ClusterResponse", result);
                return result;
            }

        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            Log.v("ClusterResponse", s);
        }
    }).execute();

在我的代码中,我用原始值替换了用户名和密码。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-11 19:06:42

我找到线索了。我正在发布我的代码,这样下一个人就可以更快地得到正确的代码。

我的错误-需要得到而不是后授权应该是base64与NOWRAP,所以它不会添加"CR“行的末尾。

代码语言:javascript
复制
(new AsyncTask<Void, Void, String>() {
        @Override
        protected String doInBackground(Void... params) {
      String result = "";
            try {

                String requestString = "https://api-eu.clusterpoint.com/908/users/";

                HttpClient httpClient = new DefaultHttpClient();
                HttpGet httpget = new HttpGet(requestString);
                ResponseHandler<String> responseHandler = new BasicResponseHandler();

                httpget.addHeader("Authorization", "Basic "+Base64.encodeToString
                        ("username:password".getBytes(),Base64.NO_WRAP));

                result = httpClient.execute(httpget, responseHandler);
            } catch (IOException e) {
                result = e.toString();
                e.printStackTrace();
            } finally {
                Log.v("ClusterResponse", "Done");
                return result;
            }

        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            Toast.makeText(getBaseContext(), s, Toast.LENGTH_LONG).show();
            Log.v("ClusterResponse", s);
        }
    }).execute();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30784134

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档