从OpenStack Keystone验证Android应用程序上的用户名密码

时间:2019-01-03 19:17:08

标签: android json httpclient keystone openstack-keystone

我参考了以下示例OpenStack- KeyStone connection to Android Project

但是它返回了http / 1.1 400错误的请求。

以下一行是错误的。我不能在StringEntity()中使用json参数

StringEntity params1 = new   StringEntity(auth.toJSONString());

您能告诉我为什么我的代码不起作用吗?

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://x.x.x.x:5000/v3/auth/tokens");
JSONObject auth = new JSONObject();
JSONObject json = new JSONObject();
auth.put("auth", json);

JSONObject pCredentials = new JSONObject();
json.put("passwordCredentials:", pCredentials);
pCredentials.put("username", "user");
pCredentials.put("password", "password");


json.put("tenantName","weatherdata");

Log.i("TAG", "passing your data"+auth.toString());

StringEntity params1 = new   StringEntity(auth.toString());
params1.setContentEncoding("UTF-8");
params1.setContentType("application/json");

httppost.setHeader("Content-type", "application/json");

httppost.setEntity(params1);

// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
Log.i("TAG", "Server response is "+response);

0 个答案:

没有答案