[英]OpenStack- KeyStone connection to Android Project
我正在嘗試從我的Android項目連接到Openstack KeyStone。 基本上我想通過openstack提供的api連接到它。 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
}
您是否在Java代碼中缺少TenantID?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.