1

我正在尝试从我的 android 项目连接到 Openstack KeyStone。基本上我试图通过 api openstack 提供的连接到它。PHP格式是。

curl -k -X 'POST' -v ####//###########/##/### -d '{"auth":{"passwordCredentials":{"用户名”:“joecool”,“密码”:“coolword”},“tenantId”:“5”}}' -H '内容类型:应用程序/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
        } 
4

1 回答 1

0

Are you missing TenantID in the Java code?

于 2013-11-20T13:35:52.273 回答