簡體   English   中英

如何共享數據庫Android應用程序和.net Web應用程序?

[英]How can I share database android application and a .net web application?

我想在使用Asp.net的android應用程序和Web應用程序構建之間共享數據庫(我的數據庫基於IIS服務器。)我只想找到可用的方法,以及是否可以將php服務與IIS服務器。

如果有人可以幫助我,我將非常感激。

萬種方式。 我可以為您提供這一建議:創建REST或SOAP服務,它將使用您需要的所有方法訪問數據庫。 現在,在android應用程序和ASP.NET應用程序中,您可以“詢問”服務以創建/更新/刪除/執行某些操作。

請嘗試以下代碼。希望它將解決您的查詢。

/**
 * This method is used for getting user response after sending request to server. 
 * It returns the response after executing url request.
 * @param params
 * @return
 */
public  String  getJSONObject(String params)
    {
        try
        {
             URL url = null;
             String response = null;
             String parameters = "param1=value1&param2=value2";
             //url = new URL("http://www.somedomain.com/sendGetData.php");
             url = new URL(params);
             //create the connection
             HttpURLConnection connection = (HttpURLConnection) url.openConnection();
             connection.setDoOutput(true);
             connection.setReadTimeout(40000);
             connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
             //set the request method to GET
             connection.setRequestMethod("GET");
             //get the output stream from the connection you created
             OutputStreamWriter request = new OutputStreamWriter(connection.getOutputStream());
             //write your data to the ouputstream
             request.write(parameters);
             request.flush();
             request.close();
             String line = "";
             //create your inputsream
             InputStreamReader isr = new InputStreamReader(
                     connection.getInputStream());
             //read in the data from input stream, this can be done a variety of ways
             BufferedReader reader = new BufferedReader(isr);
             StringBuilder sb = new StringBuilder();
             while ((line = reader.readLine()) != null) {
                 sb.append(line + "\n");
             }
             //get the string version of the response data
             response = sb.toString();
             //do what you want with the data now

             //always remember to close your input and output streams 
             isr.close();
             reader.close();
         } 
        catch (Exception e) 
        {
            Log.e("HTTP GET:", e.toString());
            response="";
         }

        return response;
   }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM