2016-02-28 108 views
0

我正在編寫一個Android應用程序,該應用程序連接到用於提供數據的數據中心(Windows PC),例如FTP服務器和其他文件。我需要應用程序使用用戶名和密碼向數據中心進行身份驗證,以便您必須先登錄才能訪問PC上的任何內容。我熟悉使用PHP登錄網站,但除了網站以外沒有任何其他登錄信息。我發現了有關Apache Shiro或Spring Security的一些信息,但我找不到任何簡單的例子。此外,它還可以作爲代理使用,在未登錄時阻止到PC的流量,並在登錄時允許流量。任何人都可以推薦一種簡單的方法來使用PC驗證我的應用程序嗎?PC和Android之間的身份驗證

+0

'需要的應用程序認證到datacenter'。很模糊。哪個協議?什麼樣的數據中心服務器? – greenapps

+1

我還沒有真正想出一個協議來做到這一點,那就是問題所在。數據中心實際上充當網絡入口的角色,並且它運行着一個MySQL數據庫來記錄流量信息,但它並沒有爲網站提供服務。我所說的數據中心只是一臺安裝了MySQL的Windows 10電腦,而Wireshark則用於記錄流量數據。 –

+0

'我還沒有真正想出一個協議來做到這一點,'。 ???您不必制定協議。你必須弄清楚使用哪種協議。那麼你必須使用哪個協議。一旦你知道你可以實現該協議。 – greenapps

回答

0

在Apache服務器的PHP代碼是

<?PHP 
    $con= 
    "(DESCRIPTION = 
    (ADDRESS = (PROTOCOL = TCP)(HOST = your_ip)(PORT = 1521)) 
    (CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = database_name) 
    ) 
    )"; 
    $conn = ocilogon("User_name", "password",$con,"WE8ISO8859P15"); 

    $query = "Select * from tablename"; 

    $parseresults = ociparse($conn, $query); 
    ociexecute($parseresults); 

    while($row=oci_fetch_assoc($parseresults)) 

    $output[]=$row; 

    print json_encode($output); 

    oci_free_statement($parseresults); 
    oci_close($conn); 
    ?> 

在Android中,你可以使用

public class UploadAsyncTask extends AsyncTask<Void, Void, String> { 
Context context; 

String result; 

public UploadActivity(Context context) { 
    this.context = context; 
} 

@SuppressWarnings("static-access") 
@Override 
protected void onPreExecute() { 
    super.onPreExecute(); 


} 

@Override 
protected String doInBackground(Void... params) { 
    // TODO Auto-generated method stub 


    final List<Pair<String, String>> postParameters = new ArrayList<>(); 



    Database db= new Database(context); 
    db.open(); 
    String activity[][] = db.uploadActivity(); 
    db.close(); 
    if(activity!=null&&!activity[0].equals(null)) { 
     for (int i = 0; i < activity[0].length; i++) { 

      postParameters.add(new Pair<>("var1", activity[i][0]); 

      result = null; 


      try { 

       String response = CustomHttpClient.execute(
         URL + "UPLOAD_DATA.php", postParameters); 
       result = response.toString(); 
       result = result.replaceAll("(\r\n|\n)", ""); 

      } catch (Exception e) { 

       Log.e("log_tag_ms", "Error in http connection!!" + e.toString()); 

      } 

     } 
    } 

    return null; 
} 

protected void onPostExecute(String result) { 
    super.onPostExecute(result); 


    } 
} 
+0

謝謝,但它只是一個例子............ –

+0

所有你的代碼沒有意義,因爲OP要求其他信息。 – greenapps

+0

抱歉,我無法理解你 –