我创建了一个应用程序,它使用 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);
}
请给我一些想法。先感谢您。