0

我创建了一个应用程序,它使用 php 从 mysql 获取数据。但是当我从我的 android 应用程序调用 php 文件时,我在我的 LogCat 窗口中得到了跟踪。

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>

但是当我使用 wamp 服务器运行 .php 时,它可以成功获取数据。我不明白我在哪里犯了错误。

以下是我的安卓代码

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

请给我一些想法。先感谢您。

4

3 回答 3

3

1)以下是相关信息:

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

2) 这来自您的 Windows 服务器。

您有权从您的 Android 手机“接触”互联网。

3)您没有授予远程客户端(不仅是Android,还有网络上任何其他PC上的任何Web浏览器)访问文件的权限。

建议:

4) 检查您的 Web 服务器根目录的 httpd.conf 和/或 .htaccess 权限。

这是一个很好的链接和一个很好的例子:

于 2012-08-27T05:09:50.773 回答
0

您的错误日志显示您忘记在AndroidManifest.xml,

只需在您的AndroidManifest.xml文件中写入以下权限。

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
于 2012-08-27T05:04:18.120 回答
0

检查您的 Android 清单中是否有互联网权限:

<uses-permission android:name="android.permission.INTERNET" />
于 2012-08-27T05:04:19.487 回答