如何将 Clusterpoint 数据库连接到 android 应用程序
How to connect Clusterpoint database to an android appliaction
我是 NoSQL 数据库和云的新手。我正在尝试使用 Clusterpoint (DBAAS) 在 android 中开发一个简单的应用程序。我尝试并搜索了很多可能性,但它不是很有效。
(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();
在我的代码中,我用原始值替换了用户名和密码。
我找到连接了。我正在发布我的代码,以便下一个人可以更快地正确完成它
我的错误
- 需要 GET 而不是 POST
- 授权应该是带有 NOWRAP 的 base64,所以它不会在末尾添加 "CR" 行。
(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();
我是 NoSQL 数据库和云的新手。我正在尝试使用 Clusterpoint (DBAAS) 在 android 中开发一个简单的应用程序。我尝试并搜索了很多可能性,但它不是很有效。
(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();
在我的代码中,我用原始值替换了用户名和密码。
我找到连接了。我正在发布我的代码,以便下一个人可以更快地正确完成它
我的错误 - 需要 GET 而不是 POST - 授权应该是带有 NOWRAP 的 base64,所以它不会在末尾添加 "CR" 行。
(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();