OpenStack- KeyStone与Android Project的连接 [英] OpenStack- KeyStone connection to Android Project
问题描述
我正在尝试从我的android项目连接到Openstack KeyStone. 基本上我想通过openstack给出的api连接到它. PHP格式是.
I'm trying to connect to to Openstack KeyStone from my android project. Basically I'm trying to connect to it by the api openstack has given. PHP format is.
curl -k -X'POST'-v ####//###########/##/### -d'{"auth":{"passwordCredentials" :{"username":"joecool","password":"coolword"},"tenantId":"5"}}'-H'内容类型:application/json'
curl -k -X 'POST' -v ####//############/##/### -d '{"auth":{"passwordCredentials":{"username": "joecool", "password":"coolword"}, "tenantId":"5"}}' -H 'Content-type: application/json'
现在我正试图将其集成到Android上的Java中' 但是过去几天,我一直坚持这一点. PHP可以完美连接. 我不确定Java代码有什么问题. 有人,请给我一个解决方法.谢谢! 这是我的代码:
Now i'm trying to integrate this on java on android' But I've been stuck on this for past few days. PHP can perfectly connect. I'm not sure what's wrong with my code in java. Anyone, please give me an idea how to solve this. Thanks! This is my code:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("####//############/##/###");
try {
JSONObject auth = new JSONObject();
JSONObject json = new JSONObject();
auth.put("auth", json);
JSONObject pCredentials = new JSONObject();
json.put("passwordCredentials:", pCredentials);
pCredentials.put("username", "admin");
pCredentials.put("password", "admin");
Log.i("TAG", "passing your data"+auth.toString());
StringEntity params1 = new StringEntity(auth.toJSONString());
params1.setContentEncoding("UTF-8");
params1.setContentType("application/json");
httppost.setHeader("Content-type", "application/json");
((HttpResponse) httppost).setEntity((params1));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
Log.i("TAG", "Server response is "+response.toString());
}catch (IOException e) {
Log.e("TAG", "IOException" + e.toString());
// TODO Auto-generated catch block
}
推荐答案
您是否在Java代码中缺少TenantID?
Are you missing TenantID in the Java code?
这篇关于OpenStack- KeyStone与Android Project的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!