2015-07-03 73 views
0

我正在开发一个第三方网站的Android应用程序,我无法控制。要使用该网站用户,必须先登录。登录是使用HTML表单在该网站上完成的。登录详细信息通过POST方法发送到服务器,操作正在调用PHP文件。 我想使用我的android应用程序进行登录。但我不喜欢加载Web视图并显示网页。我想在编辑文本框中输入用户名和密码,并以编程方式调用提交按钮。开发Android应用程序的登录屏幕

我搜索了很多,但找不到答案与我的需要相匹配。

任何人都可以发布一个完整的答案或一个源代码的链接?

+0

什么是PHP文件的预期键值参数? – andrewdleach

+0

[执行通过Android应用登录https网站](http://stackoverflow.com/questions/6443401/performing-login-to-https-website-via-android-app) – Pztar

+0

@andrewdleach用户名和密码 –

回答

0

下面是一段代码,你的问题......

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; 
    } 

你需要根据你自己的代码设计修改,但这显示了基本的结构。