0

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"));

try{
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://10.167.122.24 /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");
    }
    is.close();
    result=sb.toString();
    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.

3
  • 2
    did your server have htaccess authentication ? Commented Aug 27, 2012 at 5:03
  • thank you for suggest me but can you please tell me where i can find htaccess authentication. i having use wamp server in my local machine. waiting for your replay......... Commented Aug 27, 2012 at 5:21
  • when you open this url in browser it will ask for credential if your server have htaccess authentication.. Commented Aug 27, 2012 at 6:18

3 Answers 3

3

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.

SUGGESTION:

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

Here's a good link and a good example:

Sign up to request clarification or add additional context in comments.

2 Comments

thank you very much to replay me. But can you please tell me in brief where htaccess permission i can found in web server root directory. I having use wamp server.
@alex_android_dev - I would start with <Directory> in your http.conf file. There are many links that explain it, including the one that I cited, and the WAMP documentation. Good luck!
0

Your error logs says that you have forgot to give Internet Permission in your AndroidManifest.xml,

Just write following permission in your AndroidManifest.xml file.

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

3 Comments

Really? Surely that 403 is coming back from the server, not being generated within Android?
@therefromhere - you're absolutely correct. This is an error 403 from the server. Android is successfully connecting to the WAMP server.
ya and also i have already put that permission in my androidmanifest
0

Check if you have internet permissions in your Android manifest:

<uses-permission android:name="android.permission.INTERNET" />

2 Comments

ya i have already put that permission in my androidmanifest.xml
ahh I'm sorry :/ and also I didn't see that someone also posted that answer. I think we posted at the same time ><... I'll look at other options but @paulsm4 seems pretty plausible

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.