【发布时间】:2013-11-20 08:56:15
【问题描述】:
我正在尝试从我的 android 项目连接到 Openstack KeyStone。 基本上我试图通过 api openstack 提供的连接到它。 PHP格式是。
curl -k -X 'POST' -v ####//############/##/### -d '{"auth":{"passwordCredentials" :{"username": "joecool", "password":"coolword"}, "tenantId":"5"}}' -H 'Content-type: application/json'
现在我正在尝试将它集成到 android 上的 java 上' 但过去几天我一直坚持这一点。 PHP可以完美连接。 我不确定我在 java 中的代码有什么问题。 任何人,请给我一个想法如何解决这个问题。谢谢! 这是我的代码:
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 android openstack openstack-swift keystone