0


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

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 的文件。
谢谢你。


编辑:如果我使用 localhost/mySite/myFile.php 我可以访问它,但如果我使用 localhost/mySite/myFile.php 我无法访问它。
但我不能使用 localhost 因为我使用的是模拟器,并且 localhost/127.0.0.1 返回模拟的电话。
希望这可以帮助。

4

2 回答 2

0

环顾一番后修复了它。该问题已通过此处的解决方案“e”解决。
问题在于最初受到约束的 apache 服务器。

于 2011-09-10T00:31:45.577 回答
0

好吧,这很容易。例如,如果您想通过 chrome 或标准 Internet Explorer 在您的 android 设备上访问 test.php 文件。

首先将您的php文件保存在

c:/wamp/www/testfolder

二开

wamp/别名

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

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

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

于 2015-06-27T22:09:41.017 回答