开发Android应用程序的登录屏幕
问题描述:
我正在开发一个第三方网站的Android应用程序,我无法控制。要使用该网站用户,必须先登录。登录是使用HTML表单在该网站上完成的。登录详细信息通过POST方法发送到服务器,操作正在调用PHP文件。 我想使用我的android应用程序进行登录。但我不喜欢加载Web视图并显示网页。我想在编辑文本框中输入用户名和密码,并以编程方式调用提交按钮。开发Android应用程序的登录屏幕
我搜索了很多,但找不到答案与我的需要相匹配。
任何人都可以发布一个完整的答案或一个源代码的链接?
答
下面是一段代码,你的问题......
private static class UserLogin extends AsyncTask<Void, Integer, String> {
protected String doInBackground(Void... userLogin) {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("//domain//file.php?username=UN&password=&PW);
String result;
String userID = null;
try {
HttpResponse response = httpClient.execute(httpPost);
result = EntityUtils.toString(response.getEntity());
if (requestBuilder.jSONResultIsSuccess(result))
userID = requestBuilder.jSONUserID(result);
} catch (IOException | JSONException e) {
e.printStackTrace();
}
return userID;
}
你需要根据你自己的代码设计修改,但这显示了基本的结构。
什么是PHP文件的预期键值参数? – andrewdleach
[执行通过Android应用登录https网站](http://*.com/questions/6443401/performing-login-to-https-website-via-android-app) – Pztar
@andrewdleach用户名和密码 –