2017-04-26 154 views

回答

0

百万方法。我可以为您提供这方面的建议:创建REST或SOAP服务,使用您需要的所有方法访问数据库。现在在Android应用程序和ASP.NET应用程序中,您可以“询问”您的服务以创建/更新/删除/执行某些操作。

+0

感谢@dikkini为您的快速答案,抱歉,但因为我是初学者我不知道我是否可以使用PHP REST服务与IIS服务器? – Caroline

0

尝试使用下面的代码。希望它能解决您的查询。

/** 
* 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; 
    } 
相关问题