禁止:没有权限访问/***.php在本地主机错误


forbidden : no permission to access /***.php on localhost error


我正在尝试从本地主机上的页面读取响应。
我有以下代码:

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://myIpAddress/mySite/myFile.php");
        try {
            // Add your data
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("send_xml", "true"));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);
            InputStream is=response.getEntity().getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(is));
            StringBuilder sb = new StringBuilder();
            String line = null;
            try {
                while ((line = reader.readLine()) != null) {
                    sb.append(line + "'n");
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            Log.e(tag, "response: "+sb.toString());
        } catch (Exception e) {
            Log.e(tag, "error: "+e.toString());
        }


我在logcat中得到以下响应:

09-09 20:56:19.151: ERROR/ca(507): response: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
09-09 20:56:19.151: ERROR/ca(507): <html><head>
09-09 20:56:19.151: ERROR/ca(507): <title>403 Forbidden</title>
09-09 20:56:19.151: ERROR/ca(507): </head><body>
09-09 20:56:19.151: ERROR/ca(507): <h1>Forbidden</h1>
09-09 20:56:19.151: ERROR/ca(507): <p>You don't have permission to access /mySite/myFile.php
09-09 20:56:19.151: ERROR/ca(507): on this server.</p>
09-09 20:56:19.151: ERROR/ca(507): </body></html>
我有wamp, PHP 5.3.5, Apache 2.2.17, MySQL 5.5.8。
为什么我不能访问本地主机上的文件?解决方案是什么?
我在mySite文件夹中有一个名为index.html的文件。
谢谢。


EDIT:如果我使用localhost/mySite/myFile.php我可以访问它,但如果我使用localhost/mySite/myFile.php我无法访问它。
但是我不能使用localhost,因为我正在使用模拟器和localhost/127.0.0.1返回模拟的电话。
希望这对你有帮助。

经过一番观察,修复了它。这个问题由这里的解e来解。
问题是apache服务器最初受到约束。

这很简单。例如,如果你想在android设备上通过chrome或标准Internet explorer访问test.php文件。

首先将PHP文件保存在 中

c:/里面/www/testfolder

second open

里面/别名

目录,并创建一个配置文件(对我来说,testfolder.conf),并在这些代码中写入:

    <Directory "c:/wamp/www/testfolder/">
  Options Indexes FollowSymLinks MultiViews
    AllowOverride all
        Require all granted
    Allow from all
    Allow from all
</Directory>

,保存并关闭。重新启动wampserver,完成!