【发布时间】:2014-03-25 08:58:32
【问题描述】:
您好我正在开发一个android应用程序,数据库是localhost中使用的数据库的精确副本,也就是说android db和php db中使用的字段数是相同的。我在 php db 中所做的任何条目都应该同步到 android db。我正在为php端和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
}
}
我收到一条错误消息 - 连接到"http://ip_of_localhost/final_year_receive_request.php" 被拒绝
【问题讨论】:
-
代码中请避免使用制表符,缩进最好使用4个空格