gpt4 book ai didi

java - OpenStack-KeyStone 与 Android 项目的连接

转载 作者:太空宇宙 更新时间:2023-11-04 15:23:46 25 4
gpt4 key购买 nike

我正在尝试从我的 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?

关于java - OpenStack-KeyStone 与 Android 项目的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20091298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com