Android プロジェクトから Openstack KeyStone に接続しようとしています。基本的に、openstack が提供する API で接続しようとしています。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
}