[英]Can't get data from MySql with using php to Android?
我创建了一个应用程序,可以使用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 Server运行.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);
}
请给我一些想法。 先感谢您。
1)这是相关的消息:
You don't have permission to access /PHP/getAllPeopleBornAfter.php
2)这来自您的Windows服务器。
您拥有从Android手机“延伸”互联网的权限。
3)您没有授予远程客户端(不仅是Android,而且是network()上任何其他PC上的任何 Web浏览器)对文件的访问权限。
建议:
4)检查您的Web服务器根目录的httpd.conf和/或.htaccess权限。
这是一个很好的链接和一个很好的例子:
http://forum.wampserver.com/read.php?2,49649
# onlineoffline tag - don't remove Order Deny,Allow Deny from all Allow from 127.0.0.1 Allow from IP_ADDRESS_ABC ... Allow from IP_ADDRESS_XYZ </Directory>
您的错误日志表明您忘记了在AndroidManifest.xml
授予Internet权限,
只需在您的AndroidManifest.xml
文件中写入以下权限。
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
检查您的Android清单中是否具有Internet权限:
<uses-permission android:name="android.permission.INTERNET" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.