我是NoSQL数据库和云的新手。我正在尝试使用集群点(集群点)在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();在我的代码中,我用原始值替换了用户名和密码。
发布于 2015-06-11 19:06:42
我找到线索了。我正在发布我的代码,这样下一个人就可以更快地得到正确的代码。
我的错误-需要得到而不是后授权应该是base64与NOWRAP,所以它不会添加"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();https://stackoverflow.com/questions/30784134
复制相似问题