dsewbh5588 2011-09-09 22:12
浏览 65
已采纳

禁止访问:无权访问本地主机错误的/***.php


I am trying to read the response from a page on localhost.
I have the following code:

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 + "
");
                }
            } 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());
        }


I am getting the following response in 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>

I have wamp, with PHP 5.3.5, Apache 2.2.17, MySQL 5.5.8.
Why am I not able to access files on localhost?
What is the solution?
I have a file called index.html in the folder mySite.
Thank you.


EDIT: If I use localhost/mySite/myFile.php I am able to access it, but if I use localhost/mySite/myFile.php I am not able to access it.
But I cannot use localhost because I am using an emulator and localhost/127.0.0.1 returns the emulated phone.
Hope this helps.

  • 写回答

2条回答 默认 最新

  • douao1854 2011-09-10 00:31
    关注

    After some looking around fixed it. The problem was solved by solution 'e' here.
    Problem was with the apache server being constrained initially.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元