我想在使用Asp.net的Android应用程序和Web应用程序之间共享数据库(我的数据库基于IIS服务器)。 我只想找到可行的方法来完成它,如果我可以使用php服务与IIS服务器。如何共享数据库android应用程序和.net Web应用程序?
如果有人能帮助我,我会非常感激。
我想在使用Asp.net的Android应用程序和Web应用程序之间共享数据库(我的数据库基于IIS服务器)。 我只想找到可行的方法来完成它,如果我可以使用php服务与IIS服务器。如何共享数据库android应用程序和.net Web应用程序?
如果有人能帮助我,我会非常感激。
百万方法。我可以为您提供这方面的建议:创建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¶m2=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;
}
感谢@dikkini为您的快速答案,抱歉,但因为我是初学者我不知道我是否可以使用PHP REST服务与IIS服务器? – Caroline