您好我正在開發一個android應用程序,數據庫是本地主機使用的數據庫的確切副本,也就是說在android數據庫和php數據庫中使用的字段數是相同。我在php數據庫中創建的任何條目都應該同步到android數據庫。我正在編寫下面的代碼,用於php側和android側,請告訴我爲什麼無法連接。無法連接我的android應用程序本地主機服務器
receive_reques.php
<?php
// receive_request.php
// get the last entry from the database table
$query = "select last(Bank_Name,Account,Type,Date,Amount,Cheque_no,Cheque_party,Cheque_details) from `transaction`";
$query_run = mysql_query($query);
$response = "";
$response = mysql_fetch_row($query_run);
echo implode(":",$response);
?>
Android同步代碼:
public void postData()
{
HttpClient httpclient = new DefaultHttpClient();
// calls the local host and then the receive_request file for data values
HttpPost httppost = new HttpPost("ip_of_localhost\final_year\receive_request.php");
try{
HttpResponse response = httpclient.execute(httppost);
// convert the response received to String format
String array[] = EntityUtils.toString(response.getEntity()).split(":");
// now store them in dbms and display them in the layout
} catch (ClientProtocolException e) {
// process execption
} catch (IOException e) {
// process execption
}
}
我得到這says-連接到"http://ip_of_localhost/final_year_receive_request.php"
拒絕
在你的代碼,請避免標籤,更好的方法是使用4個空格進行縮進 – baldrs