我创建了一个应用程序,它使用php从mysql获取数据。但是,当我从我的Android应用程序调用PHP文件时,我将下面的内容放到了我的LogCat窗口中。使用PHP到Android无法从MySql获取数据?
08-26 21:07:57.748: V/(1036): Response : [email protected]
08-26 21:07:57.758: V/(1036): Entity : [email protected]
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时,它可以成功获取数据。我无法理解我犯了什么错误。
以下是我的Android代码
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);
}
请给我一些想法。先谢谢你。
没有你的服务器有htaccess的认证? –
谢谢你的建议,但你能告诉我在哪里可以找到htaccess认证。我在本地机器上使用了wamp服务器。等待你的重播......... – himAndroid
当你在浏览器中打开这个URL时,它会询问你的服务器是否有htaccess认证。 –