Hi I am developing an android application, the database is exact replica of the database used in localhost, that is to say the number of fields used in android db and php db are the same. Any entry I make in the php db should be synced to the android db. I am writing the code below for both php side and android side, please tell me why is not able to connect.
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 sync code:
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
}
}
I am getting an error which says- Connection to "http://ip_of_localhost/final_year_receive_request.php"
refused
You should use 10.0.2.2
instead of 127.0.0.1
Also note that the address 127.0.0.1 on your development machine corresponds to the emulator's own loopback interface. If you want to access services running on your development machine's loopback interface (aka 127.0.0.1 on your machine), you should use the special address 10.0.2.2 instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.