himAndroid himAndroid - 1 year ago 73
SQL Question

Can't get data from MySql with using php to Android?

I have created an app, that fetchs data from mysql using php. But when i call the php file from my android app i got following out put in my LogCat window.

08-26 21:07:57.748: V/(1036): Response : org.apache.http.message.BasicHttpResponse@44f8b018
08-26 21:07:57.758: V/(1036): Entity : org.apache.http.conn.BasicManagedEntity@44f8c730
08-26 21:07:57.839: V/(1036): Result : <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
08-26 21:07:57.839: V/(1036): <html><head>
08-26 21:07:57.839: V/(1036): <title>403 Forbidden</title>
08-26 21:07:57.839: V/(1036): </head><body>
08-26 21:07:57.839: V/(1036): <h1>Forbidden</h1>
08-26 21:07:57.839: V/(1036): <p>You don't have permission to access /PHP/getAllPeopleBornAfter.php
08-26 21:07:57.839: V/(1036): on this server.</p>
08-26 21:07:57.839: V/(1036): </body></html>

But when i run .php using wamp server then it can get data successfully. I can't understand where i have made the mistake.

Following is my android code

ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("year","1980"));

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(" /PHP/ getAllPeopleBornAfter.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();

Log.v("","Response : "+response);
Log.v("","Entity : "+entity);
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;

while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
Log.v("","Result : "+result);
}catch(Exception e){
Log.v("log_tag", "Error in http connection "+e);

Please give me some idea. Thank you in advance.

Answer Source

1) Here's the relevant message:

You don't have permission to access /PHP/getAllPeopleBornAfter.php

2) This is coming from your Windows server.

You HAVE permission to "reach out" the the internet from your Android phone.

3) You haven't given permission for remote clients (not just Android, but any web browser on any other PC on your network() access to the files.


4) Check httpd.conf and/or .htaccess permissions for your web server root directory.

Here's a good link and a good example: