OpenStack- KeyStone connection to Android Project

青春壹個敷衍的年華 提交于 2020-03-04 04:32:31

问题


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 'Content-type: application/json'

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
        } 

回答1:


Are you missing TenantID in the Java code?



来源:https://stackoverflow.com/questions/20091298/openstack-keystone-connection-to-android-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!