我正在尝试从我的android项目连接到Openstack KeyStone。 基本上我正试图通过api openstack连接到它。 PHP格式是。
curl -k -X'POST'-v #### // ############ / ## / ### -d'{“auth”:{“passwordCredentials” :{“username”:“joecool”,“password”:“coolword”},“tenantId”:“5”}}' - H'内容类型: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
}
答案 0 :(得分:0)
您是否缺少Java代码中的TenantID?