[英]AWS Identity TVM registration from android
In Identity TVM registration, Instead of redirecting the user to Identity TVM register.jsp to register, can I directly get username and password of user through my application(Because user must register to use my application) and send them to Identity TVM registration to get registered. 在Identity TVM注册中,可以直接通过我的应用程序获取用户的用户名和密码(因为用户必须注册才能使用我的应用程序),而不是将用户重定向到Identity TVM register.jsp进行注册,而是发送给Identity TVM注册以获取注册。 If yes, how to do it? 如果是,该怎么办?
I had the same problem. 我有同样的问题。 The answer I came up with is to send an HTTP Post request from within your app that replicates what happens on the registration form. 我想到的答案是从您的应用程序内发送HTTP Post请求,该请求复制注册表单上发生的事情。
You will need to create a new layout that captures the username and password (I copied the file login_menu.xml, renamed it register_menu.xml and changed some of the widget ids) 您将需要创建一个捕获用户名和密码的新布局(我复制了文件login_menu.xml,将其重命名为register_menu.xml并更改了一些小部件ID)
In the original Login.java file I changed the onclick action for the Register button to redirect to a new Activity that I called Register.java 在原始的Login.java文件中,我将“注册”按钮的onclick动作更改为重定向到我称为Register.java的新活动。
In Register.java I use the register_menu.xml as the layout file and when a person clicks the register button the following code is run (It gets run from within an AsyncTask): 在Register.java中,我使用register_menu.xml作为布局文件,当人们单击register按钮时,将运行以下代码(它从AsyncTask中运行):
String registration_url = (PropertyLoader.getInstance().useSSL() ? "https://" : "http://") + PropertyLoader.getInstance().getTokenVendingMachineURL() + "/registeruser";
URL url = new URL(registration_url);
Map<String,Object> params = new LinkedHashMap<String,Object>();
params.put("username", username);
params.put("password", password);
StringBuilder postData = new StringBuilder();
for (Map.Entry<String,Object> param : params.entrySet()) {
if (postData.length() != 0) postData.append('&');
postData.append(URLEncoder.encode(param.getKey(), "UTF-8"));
postData.append('=');
postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));
}
byte[] postDataBytes = postData.toString().getBytes("UTF-8");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setReadTimeout(10000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setInstanceFollowRedirects(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
conn.setUseCaches (false);
conn.getOutputStream().write(postDataBytes);
conn.getOutputStream().flush();
response = conn.getResponseCode();
Log.d(DEBUG_TAG, "The response is: " + response);
return response;
I picked up some of the code from other StackOverflow posts about how to generate an HTTP Post using Java ( Java - sending HTTP parameters via POST method easily ) and from the Android Dev site about network connection best practices ( http://developer.android.com/training/basics/network-ops/connecting.html ) 我从其他StackOverflow帖子中获得了一些代码,这些代码与如何使用Java生成HTTP帖子( Java-通过POST方法轻松发送HTTP参数 )以及从Android Dev站点中获取了一些有关网络连接最佳做法的代码( http://developer.android .com / training / basics / network-ops / connecting.html )
This should help you get started on your own implementation. 这应该可以帮助您开始自己的实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.