2015-07-03 56 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; 
    } 

你需要根據你自己的代碼設計修改,但這顯示了基本的結構。