【发布时间】:2018-11-04 15:51:57
【问题描述】:
我正在向我的 android 应用程序添加用户登录,以提高安全性并识别用户。我有一个登录屏幕,用户首先从下拉列表中选择他们的名字。然后将他们的选择存储在一个名为userName 的变量中。
然后我有 6 个框,用户可以在其中输入他们唯一的 pin,并将其保存到名为 userPin 的变量中。
我有一个 oracle 数据库表,其中包含每个员工的用户名和 pin,并且当前有一个 REST 服务,我正在使用该服务将数据从我的应用程序发送到同一架构中的不同表。
我的问题是...我如何首先执行 GET 请求以从我的 oracle 数据库中获取与用户选择的用户名相关联的 userPin?
任何帮助将不胜感激!
代码尝试:
private class AsyncTaskRunner extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... params) {
try {
String url = "http://xxx.xx.xxx.xx:xxxx/engAppApi/webservices/userTable/Employee_Name=" + employee;
URL object = new URL(url);
HttpURLConnection con = (HttpURLConnection) object.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept", "application/json");
con.setRequestMethod("GET");
if (con.getResponseCode() == HttpsURLConnection.HTTP_OK) {
String line;
BufferedReader br=new BufferedReader(new InputStreamReader(con.getInputStream()));
while ((line=br.readLine()) != null) {
userPinRetrieved+=line;
}
}
} catch (Exception e) {
Log.v("ErrorAPP", e.toString());
}
return "";
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
}
}
}
【问题讨论】:
-
分享您的代码并解释您卡在哪里以及您遇到的错误是什么
-
@Thunder 代码添加
标签: java android rest login get